Serialstring on one pin of the 16F84
Serialstring on one pin of the 16F84
I am trying to comunicate with the 16F84 thru a MAX232 on one one pin of the 16F84. How can I send and recive serial strings on one pin?
This is my project, but I dont understand the C language: http://www.blitzlogic.com/temp.htm
How can I decide what comunicationspeed I want to use?
This is my project, but I dont understand the C language: http://www.blitzlogic.com/temp.htm
How can I decide what comunicationspeed I want to use?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hi Urfalo
To achieve this you need to adopt a bit banging approach. Since you are using the 16F84 there is no serial UART port so all of the serial communication must be achieved through software. The communication speed or baud rate of the serial data must be compatible with your max232 device. This will probably be found in the device datasheet. The baud rate can be calulated as throughput per second. eg bytes with start and stop bits per second.
To achieve this you need to adopt a bit banging approach. Since you are using the 16F84 there is no serial UART port so all of the serial communication must be achieved through software. The communication speed or baud rate of the serial data must be compatible with your max232 device. This will probably be found in the device datasheet. The baud rate can be calulated as throughput per second. eg bytes with start and stop bits per second.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
This MAX232 is just a stupid device thath transform the RS232 +- 10 to 0 to 5v, so the speed is defined by the prosessor. I see they have used a C example, but can the pins on the prosessor be defined like this? I have tryed to copy paste the examples and put them in a C module in Flowcart, but I get several error messages.
#include <16F84.H>
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)
#include
main() {
byte value;
init_temp();
do {
value = read_temp();
printf("%u\r\n",value);
delay_ms(1000);
}while (TRUE);
}
#include <16F84.H>
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)
#include
main() {
byte value;
init_temp();
do {
value = read_temp();
printf("%u\r\n",value);
delay_ms(1000);
}while (TRUE);
}
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
I can see why your compiler is throwing up errors. This C code you are using is obviously from some kind of smart compiler which uses code to drive the PICmicros UART device.
Since the PICmicro your using (16F84) has no UART device the only way you will be able to send or recieve the serial data is to clock the data in or out one bit at a time. The easiest way to do this is to set up a loop of 10 cycles.
1st cycle outputs a logic 0 - start bit
2nd - 9th cycle outputs the data going LSB / MSB first not sure which
10th cycle outputs a logic 1 - stop bit
Between each cycle you will need a delay. If you times this delay by 10 (no of cycles) and then devide 1 by this number (1 / total time) you will get the baud rate of your system. By varying the delay you vary the baud rate. Therefore if you wanted a baud rate of 9600, each bit delay would equal.
((1 / 9600) / 10) seconds
Reading a value in would follow the same process of
waiting for a logic 0 - start bit
delaying the correct amount of time
reading in the 1st bit of data
delaying the correct amount of time
etc....
Since the PICmicro your using (16F84) has no UART device the only way you will be able to send or recieve the serial data is to clock the data in or out one bit at a time. The easiest way to do this is to set up a loop of 10 cycles.
1st cycle outputs a logic 0 - start bit
2nd - 9th cycle outputs the data going LSB / MSB first not sure which
10th cycle outputs a logic 1 - stop bit
Between each cycle you will need a delay. If you times this delay by 10 (no of cycles) and then devide 1 by this number (1 / total time) you will get the baud rate of your system. By varying the delay you vary the baud rate. Therefore if you wanted a baud rate of 9600, each bit delay would equal.
((1 / 9600) / 10) seconds
Reading a value in would follow the same process of
waiting for a logic 0 - start bit
delaying the correct amount of time
reading in the 1st bit of data
delaying the correct amount of time
etc....
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Time
I have read in the RS232 protocol that i have to use 104uS for every byte in 9600bps, but in flowcart the shortest amount of time I can choose is 1mS.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
In the C Code block you need to use delay_10us(10); this will create a delay of 100us. The other 4us can be taken up by the control logic that controls the serial data flow. If the delay is not long enough then the 4us can be created by using assembler embedded into a C code block eg
Code: Select all
asm
{
nop ;nop = no operation
nop
nop
nop
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Thanks.
This seams to work in one block, but when I copy paste this block I get several error messages:
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(59:2): error: unknown identifier 'txsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(59:2): error: invalid operand 'txsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(59:8): error: failed to generate expression
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(60:2): error: unknown identifier 'spbrg'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(60:2): error: invalid operand 'spbrg'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(60:8): error: failed to generate expression
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(61:2): error: unknown identifier 'rcsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(61:2): error: invalid operand 'rcsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(61:8): error: failed to generate expression
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(62:4): error: unknown identifier 'rcsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(62:4): error: invalid operand 'rcsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(62:11): error: failed to generate expression
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(64:4): error: unknown identifier 'trisc'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(64:4): error: invalid operand 'trisc'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(64:11): error: failed to generate expression
This seams to work in one block, but when I copy paste this block I get several error messages:
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(59:2): error: unknown identifier 'txsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(59:2): error: invalid operand 'txsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(59:8): error: failed to generate expression
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(60:2): error: unknown identifier 'spbrg'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(60:2): error: invalid operand 'spbrg'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(60:8): error: failed to generate expression
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(61:2): error: unknown identifier 'rcsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(61:2): error: invalid operand 'rcsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(61:8): error: failed to generate expression
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(62:4): error: unknown identifier 'rcsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(62:4): error: invalid operand 'rcsta'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(62:11): error: failed to generate expression
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(64:4): error: unknown identifier 'trisc'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(64:4): error: invalid operand 'trisc'
C:\Documents and Settings\Rudi Skanvik\My Documents\RS232.c(64:11): error: failed to generate expression
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Yes a single NOP just takes up 4 clock cycles this would have to be translated into a time equivalent to 4us. Also keep in mind that your control logic will take up clock cycles also.wont a NOP wary in time depending on the speed of the local oscillator
Secondly the error messages you are receiving are due to the fact that the 16F84 doesn't have these registers. You either have to use a PICmicro with a hardware UART or use a totally software approach. (bit banging)error: unknown identifier 'txsta'
Psudo code for the bit banging output approach would look similar to this
for (byte i = 0; i < 10; i++)
{
delay (1 bit delay / 1 10th byte delay)
switch (i)
case 0:
Output_Bit = 0; //Start Bit
Break;
case 9:
Output_Bit = 1; //Stop Bit
Break;
case default:
Output_Bit = Data_Var & 0x01; //Output Data 1 Bit at a time
Data_Var = Data_Var >> 1; //Rotate Data Variable
Break;
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel