I am also a newbie in this topic. I wrote a simple program, that should make an analog / digital conversion every second and send it via RS232 Port to a PC. But the compile gives the message "Syntax error <rs232.h>. The program looks like:
#chip 12F675, 10
#include <rs232.h>
dir PORTB in
dir PORTA out
#define SendBHigh PORTA ON
#define SendBLow PORTA OFF
A few things in your program need to be altered a bit:
rs232.h is included by default, so you don't need the #include line for it
The 12F675 has no PORTA or PORTB, instead it has GPIO. If you need to refer to a particular pin on GPIO, refer to it as GPIO.0, GPIO.1, etc. I don't know quite what pinout you've got, but the Dir lines would need to be made to look something like this:
Dir GPIO.0 Out
When defining the constants for sending, you need to use a command. For example,
#define SendAHigh Set GPIO.0 On
#define SendALow Set GPIO.0 Off
Again, you'll need to change that to whatever pin you're using to send the serial on.
Finally, you need to alter the line with ReadAD. When called ReadAD, the parameter must be AN and then a number - for example:
Messwert = ReadAD(AN1)
to read from the AN1 pin. How high the number can be depends on how many A/D pins you have on the PIC, the '675 has 4 so you can use AN0, AN1, AN2 or AN3.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Mostly you need to use GPIO and a pin number extension for your defines and making the SendAHigh and SendALow a "1" or "0" by using the "Set" command. Like:
#define SendAHigh Set GPIO.1 ON
#define SendALow Set GPIO.1 OFF
and,
ReadAD(GPIO.0)
Same with the dir, which also should be placed after the #defines.
No need to use the #include <rs232.h> as low level library's are called automatically in GCBasic.
Hopefully you are going thru a Max232 type of device to make the inverted +/-12v signal that the PC requires. Therefore, you should use "invert" instead of "normal" when initializing the serial rs232.
Do you really have a 10mhz crystal? Its alright if you do, just checking. But if you do, then GCBasic will probably complain (i.e. use a lower baud rate). If you absolutely need 9600 baud, then a higher crystal like a 20mhz or one of those that would give you next to zeror error rate. Look at the rs232.h file to see what I,m talking about.
So an example for 12f675 with a higher clock crystal to a PC:
#chip 12F675, 20
#define SendAHigh Set GPIO.1 ON
#define SendALow Set GPIO.1 OFF
dir GPIO.0 in
dir GPIO.1 out
InitSer(1,r9600,1+WaitForStart,8,1,none,invert)
start:
Messwert=ReadAD(GPIO.0)
SerSend(1, Messwert)
Wait 1 s
goto start
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hallo together,
I am also a newbie in this topic. I wrote a simple program, that should make an analog / digital conversion every second and send it via RS232 Port to a PC. But the compile gives the message "Syntax error <rs232.h>. The program looks like:
#chip 12F675, 10
#include <rs232.h>
dir PORTB in
dir PORTA out
#define SendBHigh PORTA ON
#define SendBLow PORTA OFF
InitSer(1,r9600,1+WaitForStart,8,1,none,normal)
start:
Messwert=ReadAD(PortB)
SerSend(1, Messwert)
Wait 10 10ms
goto start
Can anyone please help me?
Best regards nobody
A few things in your program need to be altered a bit:
rs232.h is included by default, so you don't need the #include line for it
The 12F675 has no PORTA or PORTB, instead it has GPIO. If you need to refer to a particular pin on GPIO, refer to it as GPIO.0, GPIO.1, etc. I don't know quite what pinout you've got, but the Dir lines would need to be made to look something like this:
Dir GPIO.0 Out
When defining the constants for sending, you need to use a command. For example,
#define SendAHigh Set GPIO.0 On
#define SendALow Set GPIO.0 Off
Again, you'll need to change that to whatever pin you're using to send the serial on.
Finally, you need to alter the line with ReadAD. When called ReadAD, the parameter must be AN and then a number - for example:
Messwert = ReadAD(AN1)
to read from the AN1 pin. How high the number can be depends on how many A/D pins you have on the PIC, the '675 has 4 so you can use AN0, AN1, AN2 or AN3.
Serial communications for the 12f675 has been discussed before http://sourceforge.net/forum/message.php?msg_id=4837667
Mostly you need to use GPIO and a pin number extension for your defines and making the SendAHigh and SendALow a "1" or "0" by using the "Set" command. Like:
#define SendAHigh Set GPIO.1 ON
#define SendALow Set GPIO.1 OFF
and,
ReadAD(GPIO.0)
Same with the dir, which also should be placed after the #defines.
No need to use the #include <rs232.h> as low level library's are called automatically in GCBasic.
Hopefully you are going thru a Max232 type of device to make the inverted +/-12v signal that the PC requires. Therefore, you should use "invert" instead of "normal" when initializing the serial rs232.
Do you really have a 10mhz crystal? Its alright if you do, just checking. But if you do, then GCBasic will probably complain (i.e. use a lower baud rate). If you absolutely need 9600 baud, then a higher crystal like a 20mhz or one of those that would give you next to zeror error rate. Look at the rs232.h file to see what I,m talking about.
So an example for 12f675 with a higher clock crystal to a PC:
#chip 12F675, 20
#define SendAHigh Set GPIO.1 ON
#define SendALow Set GPIO.1 OFF
dir GPIO.0 in
dir GPIO.1 out
InitSer(1,r9600,1+WaitForStart,8,1,none,invert)
start:
Messwert=ReadAD(GPIO.0)
SerSend(1, Messwert)
Wait 1 s
goto start
OOPs!
Spent too long on my answer. Too bad you can't edit your posts, as Hugh has pointed out about the AN0, AN1 etc.
Messwert=ReadAD(GPIO.0)
Should be:
Messwert=ReadAD(AN0)