HI,
Cant seem to troubleshoot this problem. The LCD is showing random characters, This line
Lcdout "Right: ", Dec right
is showing right: XXXX ( The XXX are random characters)
Also sometime i turn on the circuit I only see the last few characters of the word 'Right' including the random characters...
Must be a timing, or clocking issue.
IM using microcode studio with MPASMWIN
any ideas?
Ken
Code:
INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language
OSCCON = %01110000 '8 Mhz
DEFINE OSC 8
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' 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 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 1000
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
ADCON0 = %00000001 ' Configure and turn on A/D Module
TRISB = 0
TRISA = 1
right var word : oldright var word
right = 500
mainloop:
ADCON0.2 = 1 'Start Conversion
oldright = right 'Pot reading 1
ADCIN 0, right 'Read channel PORTA.0
pause 50
right = (right +oldright)/2 'Reducing the fluctuating output by taking an average
Lcdout $fe, 1 'Clear screen
Lcdout "Right: ", Dec right 'Display the decimal value
pause 100
goto mainloop
end
Bookmarks