dim ch1loop as long
dim rvalue as long
start:
ch1loop=readad10(an0)
ch1loop = ch1loop * 4883
rvalue = (ch1loop*1000)/(5000000-ch1loop)
when i use an a/d value of 95 I should get result of 102.xxxx but it is not coming out right, it works on paper, but not on the pic, what am i missing? this is for a resistance calculation usng a 12f683
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
dir gpio.5 out 'tx
dir gpio.4 in '
dir gpio.3 in '
dir gpio.2 in '
dir gpio.1 in '
dir gpio.0 in 'resistance ch1
dim lcdvalue as word
dim ch1loop as long
dim rvalue as long
Sub Ser_Init
;slight adjustment was required for 9600bps delay value
define baud 104 ;expressed as frequency in us
define halfbaud 52 ;place Read of SerRx in middle of bit
define SerTxHigh Set GPIO.5 On
define SerTxLow Set GPIO.5 Off
dir GPIO.5 out ;Tx
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
I'm downloading the new version, so can you help me get this up and runnig with the new version, im sure there will be new wording and what not to learn
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
dir gpio.5 out 'tx
dir gpio.4 in '
dir gpio.3 in '
dir gpio.2 in '
dir gpio.1 in '
dir gpio.0 in 'resistance ch1
dim ch1loop as long
dim rvalue as long
How do i make it so i can put send each character seperate, i need to put a decimal between the last two digits and also need to make it so it sends the same number of characters each time and fills the empty spots with either spaces or zeros?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
here is the section of code in question:
dim ch1loop as long
dim rvalue as long
start:
ch1loop=readad10(an0)
ch1loop = ch1loop * 4883
rvalue = (ch1loop*1000)/(5000000-ch1loop)
when i use an a/d value of 95 I should get result of 102.xxxx but it is not coming out right, it works on paper, but not on the pic, what am i missing? this is for a resistance calculation usng a 12f683
It works ok for me.
How are you determining that is it not working ?
using a terminal on m y laptop:
chip 12f683, 8 'mhz
config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
Ser_Init
dir gpio.5 out 'tx
dir gpio.4 in '
dir gpio.3 in '
dir gpio.2 in '
dir gpio.1 in '
dir gpio.0 in 'resistance ch1
dim lcdvalue as word
dim ch1loop as long
dim rvalue as long
start:
ch1loop=readad10(an0)
bin2ascii ch1loop
Xmit_rs232 (32) 'space
ch1loop = ch1loop * 4883
rvalue = (ch1loop*1000)/(5000000-ch1loop)
bin2ascii rvalue
'Xmit_rs232 (h'8A') 'send data
'Xmit_rs232 (h'A8')
'Xmit_rs232 (h'00') 'row
'Xmit_rs232 (h'01') 'col
'Xmit_rs232 (h'01') 'number of bytes
'data
'wait 3 s
'Xmit_rs232 (h'8A') 'clear display
'Xmit_rs232 (h'A8')
'Xmit_rs232 (h'FF')
'Xmit_rs232 (h'FF')
wait 2 s
'Xmit_RS232 10
Xmit_RS232 13 'line feed, carriage return
goto start
Sub Ser_Init
;slight adjustment was required for 9600bps delay value
define baud 104 ;expressed as frequency in us
define halfbaud 52 ;place Read of SerRx in middle of bit
define SerTxHigh Set GPIO.5 On
define SerTxLow Set GPIO.5 Off
dir GPIO.5 out ;Tx
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
serttho = 0
sertho = 0
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
lcdvaluetemp = lcdvalue / 10000
SERttho = LCDValueTemp + 48
if serttho<>48 then
Xmit_rs232 (Serttho)
end if
LCDValue = lcdvalue - LCDValueTemp * 10000
lcdvaluetemp = lcdvalue / 1000
SERtho = LCDValueTemp + 48
'if sertho<>48 then
Xmit_rs232 (Sertho)
'end if
LCDValue = lcdvalue - LCDValueTemp * 1000
lcdvaluetemp = lcdvalue / 100
SERCEN = LCDValueTemp + 48
Xmit_rs232 (SerCen)
LCDValue = LCDValue - LCDValueTemp * 100
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
Xmit_rs232 (Serdec)
LCDValue = LCDValue - LCDValueTemp * 10
SERUN = LCDValue + 48
'if serun<>48 then
Xmit_rs232 (46) '"."
Xmit_rs232 (Serun)
'end if
end sub
Ryan,
If you upgrade to the latest GCB, I will be glad to help. But I cannot support this
old bit-banged serial code.
Possibly someone else will have the time to sort through the code and find the problem(s)
Also please describe the problem in less vague terms. " .. is not coming out right" does not tell us very much.
Does anything come out? If so what?
Are you referring to what is shown on the LCD display or on a Terminal Application ?
Willliam
I'm downloading the new version, so can you help me get this up and runnig with the new version, im sure there will be new wording and what not to learn
okay, i hvae this now:
chip 12f683, 8 'mhz
config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
InitSer 1, r9600, 1, 8, 1, none, normal
define SendAHigh Set gpio.5 ON
define SendALow Set gpio.5 OFF
dir gpio.5 out 'tx
dir gpio.4 in '
dir gpio.3 in '
dir gpio.2 in '
dir gpio.1 in '
dir gpio.0 in 'resistance ch1
dim ch1loop as long
dim rvalue as long
start:
'SerPrint 1, ReadAD10(an0)
'SerSend 1, 32
wait 2 s
ch1loop=readad10(an0)
ch1loop = ch1loop * 4883
rvalue = (ch1loop*1000)/(5000000-ch1loop)
resist =rvalue
SerPrint 1, resist
wait 3 s
SerSend 1, 13
SerSend 1, 10
goto Start
How do i make it so i can put send each character seperate, i need to put a decimal between the last two digits and also need to make it so it sends the same number of characters each time and fills the empty spots with either spaces or zeros?
Thanks
I got it!
Good,
On another note. You do realize that your math will overflow to zero if the AD input value is greater than about 880.
880 * 4883 * 1000 = 4297040000