PDA

View Full Version : Serin



Andre_Pretorius
- 18th July 2008, 07:52
Hi there
i am trying to use serin to read a array of data from a UPS, at this stage i have used all the other serial ports, can someone give me a hint if there is a easer way instead of typing in the whole array , i have tried {str array/size} but get compile errors also my timeout does not want to work
Ann help would be appreciated

INCLUDE "MODEDEFS.BAS"

DEFINE OSC 20 ' Define crystal as 20Mhz


TRISE = %00000010

'Configure debug
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 2
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0


UPS VAR BYTE[46]

MAIN:
DEBUG "MAIN PROGRAM",13,10

GOTO READUPS
DEBUG UPS[0],UPS[1],UPS[2],UPS[3],UPS[4],UPS[5],UPS[6],UPS[7],UPS[8],UPS[9],UPS[10],UPS[11],UPS[12],_
UPS[13],UPS[14],UPS[15],UPS[16],UPS[17],UPS[18],UPS[19],UPS[20],UPS[21],UPS[22],UPS[23],UPS[24],UPS[25],UPS[26],UPS[27],UPS[28],_
UPS[29],UPS[30],UPS[31],UPS[32],UPS[33],UPS[34],UPS[35],UPS[36],UPS[37],UPS[38],UPS[39],UPS[40],UPS[41],UPS[42],UPS[43],UPS[44],UPS[45],13,10
goto MAIN


READUPS:
DEBUG "READ UPS SUBRUTINE",13,10
SEROUT PORTE.0,T2400,["Q1",13]
SERIN PORTE.1,T2400,200,MAIN,[UPS[0],UPS[1],UPS[2],UPS[3],UPS[4],UPS[5],UPS[6],UPS[7],UPS[8],UPS[9],UPS[10],UPS[11],UPS[12],_
UPS[13],UPS[14],UPS[15],UPS[16],UPS[17],UPS[18],UPS[19],UPS[20],UPS[21],UPS[22],UPS[23],UPS[24],UPS[25],UPS[26],UPS[27],UPS[28],_
UPS[29],UPS[30],UPS[31],UPS[32],UPS[33],UPS[34],UPS[35],UPS[36],UPS[37],UPS[38],UPS[39],UPS[40],UPS[41],UPS[42],UPS[43],UPS[44],UPS[45]]
GOTO MAIN

END

skimask
- 18th July 2008, 13:42
.........................dumped

skimask
- 18th July 2008, 13:43
Hi there
i am trying to use serin to read a array of data from a UPS, at this stage i have used all the other serial ports, can someone give me a hint if there is a easer way instead of typing in the whole array , i have tried {str array/size} but get compile errors also my timeout does not want to work
Ann help would be appreciated

Well, if you tried {str array/size}, then you may need to consult your manual...
Try [ str array\size ] instead.

As far as the array goes, a simple loop will do


t var byte
for t = start (0 whatever) to finish (100 whatever)
debug [ ups(t) ]
next t

Andre_Pretorius
- 18th July 2008, 19:46
For those who are interested in the code i ended up using, mabe it helps someone out there, i used the 16F877 micro

INCLUDE "MODEDEFS.BAS"

DEFINE OSC 20 ' Define crystal as 20Mhz

'Define ACDIN 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 to micro-seconds

'This Part set PORTA 0-5 an analog inputs
TRISA = %00011111 'set PORTA 0-5 as inputs
ADCON1 = %10000010 'Right justify output of ADC use vss and vdd as ref.
ADCON0 = %11100000 'FRC (clock derived from a dedicated internal oscillator)

TRISC = %10000000 'RC7 as RX(input) rest as output
TRISD = %11110000 'Set port d 0-3 as outputs and 4-7 as inputs
TRISB = %10011000
TRISE = %00000001

'Configure debug out
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 2
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0

'Configure debug in
DEFINE DEBUGIN_REG PORTE
DEFINE DEBUGIN_BIT 0
DEFINE DEBUGIN_BAUD 2400
DEFINE DEBUGIN_MODE 0

UPS VAR BYTE[46]

MAIN:
DEBUG "MAIN PROGRAM",13,10
PAUSE 2000
GOSUB READUPS
DEBUG str ups\45,13,10
goto MAIN


READUPS:
DEBUG "READ UPS SUBRUTINE",13,10
SEROUT PORTE.1,T2400,["Q1",13]
DEBUGIN 200,MAIN,[STR UPS\45]
RETURN

END

Andre_Pretorius
- 19th July 2008, 13:23
can anyone give me some isea as to why if i use the below mentioned code and i send {(227.9 218.2 221.0 031 50.1 2.29 25.0 00000001} in on debugin i get {ÀxÀ€€€€€€€€€€xÀ< €ð€€€€xþ€À€€xÀ€€€ð€€} out on debug

MAIN:
DEBUG "MAIN PROGRAM",13,10
PAUSE 2000
GOSUB READUPS
DEBUG str ups\45
goto MAIN

READUPS:
DEBUG "READ UPS SUBRUTINE",13,10
SEROUT PORTE.1,T2400,["Q1",13]
DEBUGIN 200,MAIN,[STR UPS\45]
RETURN

Andre_Pretorius
- 19th July 2008, 18:44
Found the problem debug in and out must have the same baud rate, helps to read the manual i gues