Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

code from 16f84a to 16f88

Status
Not open for further replies.

savnik

Member
How to change this code to work for 16f88
Code:
; Program "LCD.ASM"

           title      "LCD"
           processor  16F84a
           include    p16f84a.inc
           __config   _PWRTE_OFF & _WDT_OFF & _XT_OSC
           radix      DEC
           errorlevel -302
		 

#define    E          PORTB,3
#define    RS         PORTB,2
#define    DATA_PORT  PORTB      	; Only of  RB7 … RB4              
#define    DATA_DIR   TRISB


           cblock     h'0C'
SaveW
Char
Temp
Temp1
Temp2
Temp3
Temp4
Result   : 4          ; MSB first
Thousand : 2          ; MSB first
BCD0
BCD1
BCD2
BCD3
N
           endc

           org        0
           goto       START

ClearDisp  macro
           movlw      b'00000001'
           call       SEND_CMD
           call       T1mS       	; To erase the screen takes more 1mS
           endm

DataOk     macro                 	; Validation of the data
           bsf        E
           bcf        E
           endm

DDRam      macro      address
           movlw      0x80 + address
           call       SEND_CMD
           endm

Disp       macro      charvalue
           movlw      charvalue
           call       SEND_CHAR
           endm

RSCmd      macro                 	; The data are orders (RS=0)
           bcf        RS
           endm

RSChar     macro                 	; The data are characters (RS=1)
           bsf        RS
           endm

ShiftL     macro                 	; Decalage towards the left of posting
           movlw      b'00011000'
           call       SEND_CMD
           endm

;________________________________Subroutines________________________________
         
; Delays 1mS, 10mS, 100mS and 1S

T1mS
           movwf      SaveW
           movlw      .248
           movwf      Temp1
Loop1mS
           nop
           decfsz     Temp1,f
           goto       Loop1mS

           movf       SaveW,w

           return
;
T10mS
           movwf      SaveW
           movlw      .10
           movwf      Temp2
Loop10mS
           call       T1mS
           decfsz     Temp2,f
           goto       Loop10mS

           movf       SaveW,w

           return
;
T100mS
           movwf      SaveW
           movlw      .100
           movwf      Temp3
Loop100mS
           call       T1mS
           decfsz     Temp3,f
           goto       Loop100mS

           movf       SaveW,w

           return
;
T1S
           movwf      SaveW
           movlw      .100
           movwf      Temp4
Loop1S
           call       T10mS
           decfsz     Temp4,f
           goto       Loop1S

           movf       SaveW,w



;---------------------------------------------------------------------------
; Description: Transmet un caractere vers l'afficheur          
; Entr‚e: Caractere dans le registre W
; Sortie: Aucune

SEND_CHAR  
           call       T1mS       	; Attendre que l'afficheur soit pret
           RSChar                	; Afficheur en mode caract‚re
           movwf      Char       	; Sauvegarde du caract‚re
           movf       DATA_PORT,w
           andlw      0x0F
           movwf      DATA_PORT     
                                 	; Masquage: Reset du poids fort de DP
           movf       Char,W     	; On restaure le caract‚re dans W
           andlw      0xF0       	; On isole le poids fort du registre W 
           iorwf      DATA_PORT,F	; On positionne le poids fort de DATA_PORT 
           DataOk                	; On bascule le verrou du LCD
           swapf      Char,F     	; On ‚change les poids fort et faible 
           movf       DATA_PORT,w
           andlw      0x0F
           movwf      DATA_PORT
                                 	; Masquage: Reset du poids fort de DP
           movf       Char,W
           andlw      0xF0       	; On isole le poids fort du registre W 
           iorwf      DATA_PORT,F	; On positionne le poids fort de DATA_PORT 
           DataOk                	; On bascule le verrou du LCD
           retlw      0          	; Retour avec W=0

;-----------------------------------------------------------------------------
; Description: Transmet une commande vers l'afficheur          
; Entree: Commande dans le registre W
; Sortie: Aucune

SEND_CMD  
           call       T1mS       	; Attendre que l'afficheur soit prˆt
           RSCmd                 	; Afficheur en mode commande
           movwf      Char       	; Sauvegarde de la commande
           movf       DATA_PORT,w
           andlw      0x0F
           movwf      DATA_PORT   
                                 	; Masquage: Reset du poids fort de DP
           movf       Char,W     	; On restaure la commande dans W
           andlw      0xF0       	; On isole le poids fort du registre W 
           iorwf      DATA_PORT,F	; On positionne le poids fort de DATA_PORT 
           DataOk                	; On bascule le verrou du LCD
           swapf      Char,F     	; On ‚change les poids fort et faible 
           movf       DATA_PORT,w
           andlw      0x0F
           movwf      DATA_PORT    
                                 	; Masquage: Reset du poids fort de DP
           movf       Char,W
           andlw      0xF0       	; On isole le poids fort du registre W 
           iorwf      DATA_PORT,F	; On positionne le poids fort de DATA_PORT 
           DataOk                	; On bascule le verrou du LCD
           retlw      0          	; Retour avec W=0

;____________________________________main___________________________________

START      

	   bsf        STATUS,RP0
           movlw      B'00000000'
           movwf      TRISB
	   bcf        STATUS,RP0
           clrf       PORTB
           call       INIT_LCD          
           movlw      b'00001100'          
           call       SEND_CMD                     
           movlw      b'00101000'         
           call       SEND_CMD

           ClearDisp

           Disp       'F'
           Disp       'R'
           Disp       'E'

           call       T1S

           ClearDisp
       

           end
 
Last edited:
I think there's only two things you have to do to make it work on the 16F88:
1. Disable analog functions: put 0x07 into CMCON and clear ANSEL.
2. Change the PORT assignments where necessary. You'll have to consult the datasheets for this.

Mike
 
upand_at_them said:
I think there's only two things you have to do to make it work on the 16F88:
1. Disable analog functions: put 0x07 into CMCON and clear ANSEL.
2. Change the PORT assignments where necessary. You'll have to consult the datasheets for this.

Also change the GPR base address! ;)
 
upand_at_them said:
I think there's only two things you have to do to make it work on the 16F88:
1. Disable analog functions: put 0x07 into CMCON and clear ANSEL.
2. Change the PORT assignments where necessary. You'll have to consult the datasheets for this.

Mike
You don't have to put 0x07 in CMCON on the 16F88, it's the default for that chip.

Also the RAM starts at 0x20 in the 16F88 (change the cblock h'0C' to cblock 0x20)
 
Last edited:
Then you're probably running from the internal 31KHz clock. If the external clock fails to run the internal osc will take over by default.

try changing the lines to the beginning of your code (osccon is in bank 1)
Code:
  START      

     bsf        STATUS,RP0
     movlw      b'01100010'    ;B1 use internal 4MHz osc
     movwf      OSCCON
     movlw      B'00000000'
     movwf      TRISB
 
If your using the internal oscillator then you need to switch it from 32KHz to 8MHz.

Code:
		movlw	B'01110000'	;select 8MHz clock
		movwf	OSCCON
OSCCON is in bank 1.

Mike.
 
Pommie said:
If your using the internal oscillator then you need to switch it from 32KHz to 8MHz.

Code:
        movlw    B'01110000'    ;select 8MHz clock
        movwf    OSCCON
OSCCON is in bank 1.

Mike.

I think his LCD init delay loops will fail at 8MHz (assuming the 16F84 was running at 4MHz)
 
blueroomelectronics said:
Then you're probably running from the internal 31KHz clock. If the external clock fails to run the internal osc will take over by default.

try changing the lines to the beginning of your code (osccon is in bank 1)
Code:
  START      

     bsf        STATUS,RP0
     movlw      b'01100010'    ;B1 use internal 4MHz osc
     movwf      OSCCON
     movlw      B'00000000'
     movwf      TRISB
I change and now is ok.But why the external clock fails;
I use 4 MHZ Xtal (with pic16f84a i had not any problem)

I have use this for 16f88:
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
 
INTRC_IO is internal oscillator isn't it?
Use _XT_OSC instead.
This configures the PIC to use the external crystal oscillator.
 
bananasiong hit the nail on the head.

Food for thought, the internal RC is calibrated to 1% and good enough for most stuff. It's not good for a clock but then again neither is a typical 4MHz crystal over the long run it'll tend to lose minutes a month. For clocks use a 32768Hz crystal. Nice and accurate.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top