Angry Badger
Member
Hello,
I've just got my first 18F series chip - 18F4520 in fact (and it's humungous, think I'll have to get to grips with this SMT business if I'm ever to use it on a pcb). Previously I have only used a 16F690.
I've ported over the 2x16 LCD program from Nigels' tutorial having got it properley working yesterday on my 16f690 but am having a few problems getting it properley functioning on this new chip.
The first hurdle encountered has been with regard to user memory; Is it correct to place my user registers starting at 0x80 with this new chip?
The other problem encounterd is with the use of a look up table. I've now learnt that the 18F program counter increments 'in two's' and this has caused me a headache. So what is the 'standard' way to use a LUT with the 18F chips, are there some tips you can give me?
Thanks in advance for any help.
I've just got my first 18F series chip - 18F4520 in fact (and it's humungous, think I'll have to get to grips with this SMT business if I'm ever to use it on a pcb). Previously I have only used a 16F690.
I've ported over the 2x16 LCD program from Nigels' tutorial having got it properley working yesterday on my 16f690 but am having a few problems getting it properley functioning on this new chip.
The first hurdle encountered has been with regard to user memory; Is it correct to place my user registers starting at 0x80 with this new chip?
The other problem encounterd is with the use of a look up table. I've now learnt that the 18F program counter increments 'in two's' and this has caused me a headache. So what is the 'standard' way to use a LUT with the 18F chips, are there some tips you can give me?
Thanks in advance for any help.
Code:
;A project to drive a 16 x 2 LCD alphanumeric module (Powertip PC1602 from Rapid Electronics). 11 June 2009
;Most of this code is copied from Nigel Goodwins' tutorial. I've used 8 bit mode rather than 4 bit.
;
;CHANGED THE PIC FROM 16F690 TO 18F4520 AFTER GETTING IT WORKING ON THE '690
;
list p=18F4520
#include <p18F4520.inc>
errorlevel -302 ; suppress message 302 from list file
errorlevel -305
CONFIG OSC = INTIO7, FCMEN = OFF, IESO = OFF, PWRT = OFF, BOREN = OFF, WDT = OFF, MCLRE = ON, LPT1OSC = OFF, PBADEN = OFF, STVREN = OFF, LVP = OFF, XINST = OFF, DEBUG = ON
;DATA SECTION
UDATA 0x80 ;without this variables won't show in MPLAB Watch window
count RES 1
count1 RES 1
counta RES 1
countb RES 1
#define LCD_PORT PORTD
#define LCD_RS PORTB,1
#define LCD_E PORTB,0
;END OF DATA SECTION
org 0
;____________________________________________________________________________________________________________________
Start
clrf TRISB
clrf TRISD
clrf PORTB
clrf PORTD
clrf count
clrf count1
clrf counta
clrf countb
movlw b'01100010' ;4mhz
movwf OSCCON
;____________________________________________________________________________________________________________________
Main
call Delay100 ;LCD settling time
call Initialise_LCD
clrf count ;set counter register to zero
Message
movf count,w ;put counter value in W
call Text ;get a character from the text table
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
goto NextMessage
call LCD_Char
call Delay255
incf count
incf count
goto Message
;____________________________________________________________________________________________________________________
NextMessage
call LCD_Line2 ;move to 2nd row, first column
clrf count ;set counter register to zero
Message2
movf count, w ;put counter value in W
call Text2 ;get a character from the text table
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
goto EndMessage
call LCD_Char
call Delay255
incf count
incf count
goto Message2
EndMessage
Stop
goto Stop ;endless loop
;____________________________________________________________________________________________________________________
Initialise_LCD
movlw b'00111100' ;8 bit mode / 2 lines / 5x11
call LCD_CMD
movlw b'00011100' ;display shift / right shift.
call LCD_CMD
movlw b'00000110' ;Character entry mode
call LCD_CMD
movlw b'00001111' ;display on / cursor off / cursor position on
call LCD_CMD
call LCD_Clr
retlw .0
;____________________________________________________________________________________________________________________
LCD_CMD
movwf LCD_PORT
bcf LCD_RS
call Pulse_E
call Delay5
retlw .0
;____________________________________________________________________________________________________________________
LCD_Char
movwf LCD_PORT
bsf LCD_RS ;RS line to 1
call Pulse_E ;Pulse the E line high
call Delay5
retlw 0x00
;____________________________________________________________________________________________________________________
LCD_Line2
movlw 0xc0 ;move to 2nd row, first column
call LCD_CMD
retlw 0x00
LCD_Clr
movlw 0x01 ;Clear display
call LCD_CMD
retlw 0x00
;____________________________________________________________________________________________________________________
Delay255
movlw 0xff ;delay 255 mS
goto d0
Delay100
movlw d'100' ;delay 100mS
goto d0
Delay50
movlw d'50' ;delay 50mS
goto d0
Delay20
movlw d'20' ;delay 20mS
goto d0
Delay5
movlw 0x05 ;delay 5.000 ms (4 MHz clock)
d0 movwf count1
d1 movlw 0xC7 ;delay 1mS
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
;____________________________________________________________________________________________________________________
Pulse_E
bsf LCD_E
nop
bcf LCD_E
retlw .0
;____________________________________________________________________________________________________________________
Text
addwf PCL,f
nop
retlw 'H'
retlw 'e'
retlw 'l'
retlw 'l'
retlw 'o'
retlw 0x00
Text2
addwf PCL,f
nop
retlw 'r'
retlw 'e'
retlw 'a'
retlw 'd'
retlw 'y'
retlw '.'
retlw '.'
retlw '.'
retlw 0x00
end
;__________________________________________________________________________________________________________