PDA

View Full Version : Migrating from PIC16F690 to PIC18F4525 and having LCD issues



jblackann
- 6th June 2008, 18:42
Hello all. I have created a program that runs perfectly fine on a PIC16F690. The only problem is that I have run out of memory space on the 16F690 so I decided to move to a chip that has a larger memory. I am trying to use the PIC18F4525 but I cannot get the LCD to function properly. Upon power-up, I have a pin flash an LED so I know the micro is working but the display is just showing a divison sign. I am using a PICSTART Plus to program the 18F4525 and am using PICBASIC PRO 2.50A. I have the LCD attached to PORTD of the micro and I am using an external crystal that is 4 Mhz. I have tried two different LCDs but get the same results with each one.

Is there anything that discusses using PICBASIC Pro with the 18F series? I have looked through the datasheet and tried looking all through the forum. The only thing I can find is that a lot of people have problems with the configurations fuses with the 18F series. I was having problems as well but I have just commented out them out for the time being. I set the config bits in MPLAB prior to programming the 18F4525. I don't really know much about modifying the .inc files. If there are any guides on this, this would be quite helpful as well.

If anyone can please provide me with any ideas I would greatly appreciate it.

Here is a some of the code.


include "modedefs.bas"
DEFINE OSC 4
DEFINE SER2_BITS 9
DEFINE ADC_BITS 10 ' set number of bits in result
DEFINE ADC_CLOCK 5 ' set clock source
DEFINE ADC_SAMPLEUS 50 ' set sampling time for microseconds
DEFINE LCD_DREG PORTD 'set LCD DATA port
DEFINE LCD_DBIT 4 'set starting DATA bit (0 or 4) if 4-bit
DEFINE LCD_RSREG PORTD ' Set LCD Register Select port
DEFINE LCD_RSBIT 2 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTD ' Set LCD Enable port
DEFINE LCD_EBIT 3 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us

'CONFIG1H = %11000001 ' Oscillator switchover enabled
' Fail safe clock monitor enabled
' XT oscillator
'CONFIG2L = %00011000 ' Brown out reset voltage setting minimum setting
' Brown-out reset disabled
' Power up timer enabled
'CONFIG2H = %00000000 ' WDT disabled
'CONFIG3H = %00000000 ' MCLR disabled
' Timer 1 configured for High power op
' PORTB4:0 are digital IO
' CCP2 muxed with RB3
'CONFIG4L = %11000000 ' background debugger disabled
' instruction set enstions enabled
' Single suppoly ICSP enabled
' stack full/underflow will not cause a Reset
'CONFIG5L = %00000000 ' code protection bit for all blocks
'CONFIG5H = %11000000 ' Data EEPROM not protected
' Boot block not protected
'CONFIG6L = %00001111 ' no write protection bit for all blocks
'CONFIG6H = %11000000 ' no write protection bit for Data EEPROM
' and Boot Block
' Configuration is write protected
'CONFIG7L = %0000000 ' no protection for table reads
'CONFIG7H = %0100000 ' no protection for table reads for boot block


CMCON = 7
ADCON1 = %00001111 ' Voltage reference Vss
' Voltage reference Vdd
' all pins digital
'ADCON2 = ??? ' this needs to be set up if A to D used
'ANSEL = %00000000 ; all digital
'ANSELH = %00001000 ; AN11 is analog
OSCCON = %01101100 ' internal Osc of 4 MHz
WDTCON = %00000000 ' Watchdog timer is off
TRISA = %11011110 ; define Inputs and Outputs
TRISB = %10101111
TRISC = %00000000
TRISD = %00010000
TRISE = %00000000
PORTA = %00000000
PORTB = %00000000
PORTC = %00000000
PORTD = %00000000
PORTE = %00000000
LATA = %00000000 ' Data latch register
LATB = %00000000 ' Data latch register
LATC = %00000000
LATD = %00000000
LATE = %00000000
INTCON = %00000000
INTCON2 = %10000000 ' PortB pullups disabled
PIE1 = %00000000 ' disable peripheral interrupts
PIE2 = %00000000 ' disable peripheral interrupts
'OPTION_REG = %11100000
'WPUA = %00000000
'WPUB = %00000000
CCP1CON = %00001100 ' setup the PWM module for single output on RC5

'PORTA definitions
TEST_OUTPUT VAR PORTA.0
TRANSMIT_OUT VAR PORTA.4
RECEIVE_IN VAR PORTA.5

'PORTB definitions
FUNCTION_BUTTON VAR PORTB.0
UP_BUTTON VAR PORTB.1
DOWN_BUTTON VAR PORTB.2
SET_BUTTON VAR PORTB.3
'ANALOG_INPUT VAR PORTB.5
'SERIAL_OUTPUT VAR PORTB.6



AD_AN11_VALUE VAR WORD
AD_AN11_VOLT VAR WORD
UP_VENT_SETTING VAR BYTE ' WORD ' ON = VENT
UP_FILL_SETTING VAR BYTE ' WORD ' OFF = Fill
DOWN_VENT_SETTING VAR BYTE ' WORD ' ON = VENT
DOWN_FILL_SETTING VAR BYTE ' WORD ' OFF = Fill
UP_PULSES VAR BYTE
DOWN_PULSES VAR BYTE
CHECKSUM_BYTE VAR BYTE
CHECKSUM_WORD VAR WORD
REC_CHECKSUM_VALUE VAR WORD
DUTY VAR WORD
UP_VALUE VAR word
DOWN_VALUE VAR Word
UP_TRIP_ADJUST VAR WORD
DOWN_TRIP_ADJUST VAR WORD
DECAY_VALUE VAR BYTE ' WORD
TOLERANCE_VALUE_UP VAR BYTE ' WORD
TOLERANCE_VALUE_DOWN VAR BYTE

A0 VAR BYTE
A1 VAR BYTE
A2 VAR BYTE
A3 VAR BYTE
A4 VAR BYTE
C1 VAR Byte
C0 VAR BYTE
C6 VAR BYTE
C7 VAR BYTE
D0 Var Byte
D1 VAr Byte
D2 VAr Byte
D3 Var Byte
i VAR BYTE
MODE VAR BYTE ' used to determine which function
'should be incrementing
' MODE 1 A to D setting
' MODE 2 MIN SETTING
' MODE 3 MAX SETTING

UPDATE VAR BYTE 'UPDATE bit 0, used for returning from Interrupts
'UPDATE bit 1, used to indicate Manual Mode
'Update bit 2, 1 = step 1
'Update bit 3, 1 = step 2
'Update bit 4, 1 = step 3
'Update bit 5, 1 = step 4

'---------- program starts here
' 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,15,16,17, 18,19, 20, 21, 22, 23, 24, 25,26,27,28,29,30,31,32
DATA 16, 0, 30, 0, 25, 50, 50, 0, 0, 200, 0, 0, 0, 0, 16, 0, 2, 0, 29, 0, 9, 96,273, 148, 20, 20, 0, 0, 0, 0, 0, 0,00


TEST_OUTPUT = 1
PAUSE 500
TEST_OUTPUT = 0
PAUSE 500
T2CON = %00000101 ' Turn on Timer2, Prescale=4

' Use formula to determine PR2 value for a 1KHz signal,
' 4MHz clock, and prescale=4. (4E6/(4*4*1E3))-1=249

PR2 = 249 ' Set PR2 to get 1KHz out

' Use formula to determine CCPR1L:CCP1CON<5:4> value for
' ends of range 20% to 80%. (249+1)*4*0.2=200 (20% value)
' (249+1)*4*0.8=800 (80% value)
READ 8, DUTY.HIGHBYTE
READ 9, DUTY.LowBYTE
Pause 10
DUTY = DUTY


loop: CCP1CON.4 = duty.0 ' Store duty to registers as
CCP1CON.5 = duty.1 ' a 10-bit word
CCPR1L = DUTY >> 2

duty = duty + 10 ' Increase duty cycle


Pause 200 ' Wait for LCD to startup

DISPLAY_MODE_SELECT:
GOSUB CLEAR_LCD
LCDOUT "Push Function"
LCDOUT $FE, $C0, " to setup values"
LOOK_FOR_BUTTON_PUSH:
BUTTON FUNCTION_BUTTON, 1, 255, 0, A3, 1, SETUP
BUTTON SET_BUTTON, 1, 255, 0, A2, 1, CONTRAST
'GOSUB MODE_BUTTON_PUSH
PAuse 10
GOTO LOOK_FOR_BUTTON_PUSH

skimask
- 6th June 2008, 19:31
If there are any guides on this, this would be quite helpful as well.
Config fuse - a good thread on how to handle it right here -
http://www.picbasic.co.uk/forum/showthread.php?t=543&highlight=presetting+config

Try increasing your LCD startup time to 1 second.
Post the whole code. Maybe we could help you trim it down to remain in the '690.

jblackann
- 6th June 2008, 20:05
I noticed a wrong configuration with the TRISD. I changed this and was still having problems. I decided to try connecting the LCD on a different pins and it appears to work now. Here is what I did:


DEFINE LCD_DREG PORTD 'set LCD DATA port
DEFINE LCD_DBIT 0 'set starting DATA bit (0 or 4) if 4-bit
DEFINE LCD_RSREG PORTD ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTC ' Set LCD Enable port
DEFINE LCD_EBIT 3 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us


I will review the config settings thread. I will try to clean up my code and post it.