in the following code there must be a mistake, but where?
I use an EasyPic4 with a GLCD on PortB (Data) and PortD(Control). The Display works great but there are two problems:
1. The ADC should display a range between 0 and 1023 but I only get 0 till 511 (With the resistor on the EasyPic4)
2. The choice rans endless (backwards).
Here is the code:
Code: Select all
Device = 18F4620
Clock = 20
#option GLCD_MODEL = SED1520
#option GLCD_DATA = PORTB // data port
#option GLCD_RS = PORTD.5 // RS pin (control or data)
#option GLCD_RW = PORTD.4 // RW pin (read or write)
#option GLCD_CS1 = PORTD.3 // chip1 select
#option GLCD_CS2 = PORTD.6 // chip2 select
#option GLCD_ASPECT_RATIO = 0
Include "Graphics.bas"
Include "GLCD.bas"
Include "Fonts.bas"
Include "Bittmaps.bas"
Include "Convert.bas"
Include "utils.bas"
Include "ADC.bas"
Dim RES As PORTD.7, // RES pin from LCD
Choice As Byte,
nChoice As Byte,
FirstStart As Boolean,
Warnning As Boolean
Sub SetUpDisplay()
Cls
Rectangle(0,0,121,31)
SetImage(0,0,Caption)
End Sub
Sub DisplayWarnning()
Cls
Font.Style = fsNormal
SetImage(0,0,w_Message)
End Sub
SetAllDigital
TRISA = $FF
TRISC = $FF
TRISD = $FF
TRISE = $FF
Choice = 9
nChoice = 0
High(RES)
ADCON1 = $0E // AN0 enable
FirstStart = true
Warnning = false
If Warnning Then
DisplayWarnning()
DelayMS(10000)
End If
SetUpDisplay()
Repeat
If Choice <> nChoice Then
// Change the things to display
FirstStart = false
End If
Writestr(2,15,dectostr(ADC.Read(0)))
If PORTE.2 = 1 Then
If Choice = 5 Then
nChoice = 0
ElseIf Choice >=0 Then
nChoice = nChoice + 1
End If
End If
If PORTD.0 = 1 Then
If Choice = 0 Then
nChoice = 5
ElseIf Choice <=5 Then
nChoice = nChoice - 1
End If
End If
Until false
(From 0-5)
At the moment the choice ran backward (it seems that PORTD.0 was hold!?)
Has anyone an idea?
Thanks in advance
CS