For some reason with this code, the a/d readings are not right they are always the same numbers, no matter what i do to the pins? (the commented out parts are for a bigger chip)
#chip 12F675, 12 'mhz
#config MCLRE=off, WDT=off
Ser_Init
dim test as Word
dim test1 as word
#define RecAHigh GPIO.0 on
#define RecALow GPIO.0 off
Dir GPIO.0 in
Dir GPIO.1 Out
Dir GPIO.2 in
Dir GPIO.3 in
InitSer 1, r1200,1, 8, 1, none, invert
do
SerReceive 1, Temp
If Temp > 100 Then output
loop
sub output
'Xmit_Print ("1")
'wait 5 s
test = ReadAD10(AN3)
Bin2ascii (test_H)
Bin2ascii (test)
Sub Ser_Init
#define baud 833 ;the us delay for 1200 baud rate
#define SerTxHigh Set GPIO.1 on
#define SerTxLow Set GPIO.1 Off
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
sub Bin2ascii(LCDValue )#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
If LCDValue >= 100 Then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
Xmit_RS232(SerCen) 'SerSend (1,SERCEN)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
Xmit_RS232(Serdec) 'SerSend (1,SERDEC)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
Xmit_RS232(Serun) 'SerSend (1,SERUN)
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For some reason with this code, the a/d readings are not right they are always the same numbers, no matter what i do to the pins? (the commented out parts are for a bigger chip)
#chip 12F675, 12 'mhz
#config MCLRE=off, WDT=off
Ser_Init
dim test as Word
dim test1 as word
#define RecAHigh GPIO.0 on
#define RecALow GPIO.0 off
Dir GPIO.0 in
Dir GPIO.1 Out
Dir GPIO.2 in
Dir GPIO.3 in
InitSer 1, r1200,1, 8, 1, none, invert
do
SerReceive 1, Temp
If Temp > 100 Then output
loop
sub output
'Xmit_Print ("1")
'wait 5 s
test = ReadAD10(AN3)
Bin2ascii (test_H)
Bin2ascii (test)
test1 = ReadAD10(AN4)
Bin2ascii (test1_H)
Bin2ascii (test1)
end sub
Sub Ser_Init
#define baud 833 ;the us delay for 1200 baud rate
#define SerTxHigh Set GPIO.1 on
#define SerTxLow Set GPIO.1 Off
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
sub Bin2ascii(LCDValue )#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
If LCDValue >= 100 Then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
Xmit_RS232(SerCen) 'SerSend (1,SERCEN)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
Xmit_RS232(Serdec) 'SerSend (1,SERDEC)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
Xmit_RS232(Serun) 'SerSend (1,SERUN)
end sub
Are you using the internal osc, and an external one?