void UART_Init(int baudrate)
{
SCON = 0x50; // Asynchronous mode, 8-bit data and 1-stop bit
TMOD = 0x20; //Timer1 in Mode2.
TH1 = 256 - (11059200UL)/(long)(32*12*baudrate); // Load timer value for baudrate generation
TR1 = 1; //Turn ON the timer for Baud rate generation
}
void UART_TxChar(int ch)
{
SBUF = ch; // Load the data to be transmitted
while(TI==0); // Wait till the data is trasmitted
TI = 0; //Clear the Tx flag for next cycle.
}
void main()
{
while(1)
{
UART_Init(9600);
UART_TxChar(P0);
}
}
void UART_Init(int baudrate)
{
SCON = 0x50; // Asynchronous mode, 8-bit data and 1-stop bit
TMOD = 0x20; //Timer1 in Mode2.
TH1 = 256 - (11059200UL)/(long)(32*12*baudrate); // Load timer value for baudrate generation
TR1 = 1; //Turn ON the timer for Baud rate generation
}
char UART_RxChar(void)
{
while(RI==0); // Wait till the data is received
RI=0; // Clear Receive Interrupt Flag for next cycle
return(SBUF); // return the received char
}
void main()
{
segment1=0;
segment2=0;
segment3=0;
segment4=0;
while(1)
{
UART_Init(9600); //Initialize the UART module with 9600 baud rate
P0 = UART_RxChar(); // Receive a char from serial port
}
You need to expand it slightly, at the moment you are transferring the segments as a single byte, that works fine for one digit as you have seen. You need to send another 4 bits (2 if you encode them) to say which of the digits is being sent. So as well as the segment information you can tell it which of the digits the segments are from. The easiest way is to encode the segments into a four bit number (in software) and to encode the digit position in the other four bits, so you still only send 8 bits but it contains all the information instead of just one number.
Like this:
your 8 bits sent through the UART are: DDDDSSSS
where DDDD is the position of the digit in the display and SSSS is the number on that digit.
You also probably don't want to Init the UART for every byte, it should only need doing once.
Brian.
I think your original error is because there is no way to tell which digit is being sent, there is no sync between the two ends. I assume you have the segments connected to P0, what happens is the value on P0 is sent by the UART whenever it is ready to send more data. The value on P0 depends on which digit is active at the time but the UART doesn't know which it is.
Think of the UART data as being a conveyor belt between the TX and RX devices, at the TX end more is put on the belt as soon as there is a gap and at the RX end it is taken off at fixed intervals. The order of items on the conveyor cannot be guaranteed when the loading and unloading are at different rates.
Brian.
yes i have changed my code, now i am initializing it only at the time of startup. but then too the same problem arises.A faster crystal probably wont help.
The most likely problem is the way you initialize the UART. Normally the bit rate (Baud rate) is generated by it's own timer and stays running continuously when initialized. Your code resets it after every character is sent or received.
Check the data sheet on how to program the Baud rate and do it once at the start of your program, you don't need to do it again in the loop.
Brian.
here's my new code for both RX and TX BoardPlease show your new code so we can see it's current version.
A schematic of your connection to the segments would also help.
Brian.
void UART_Init(int baudrate)
{
SCON = 0x50; // Asynchronous mode, 8-bit data and 1-stop bit
TMOD = 0x20; //Timer1 in Mode2.
TH1 = 0xFD;
TR1 = 1; //Turn ON the timer for Baud rate generation
}
void UART_TxChar(int ch)
{
SBUF = ch; // Load the data to be transmitted
while(TI==0); // Wait till the data is trasmitted
TI = 0; //Clear the Tx flag for next cycle.
}
void main()
{
char seg;
UART_Init(9600);
while(1)
{
seg=P0;
UART_TxChar(seg);
}
}
void UART_Init(int baudrate)
{
SCON = 0x50; // Asynchronous mode, 8-bit data and 1-stop bit
TMOD = 0x20; //Timer1 in Mode2.
TH1 = 0xFD;
TR1 = 1; //Turn ON the timer for Baud rate generation
}
char UART_RxChar(void)
{
while(RI==0); // Wait till the data is received
RI=0; // Clear Receive Interrupt Flag for next cycle
return(SBUF); // return the received char
}
void main()
{
char seg;
UART_Init(9600); //Initialize the UART module with 9600 baud rate
segment1=0;
segment2=0;
segment3=0;
segment4=0;
while(1)
{
seg = UART_RxChar(); // Receive a char from serial port
P1=seg;
}
This is the schematic of my RX BoardPlease show your new code so we can see it's current version.
A schematic of your connection to the segments would also help.
Brian.
Please show your new code so we can see it's current version.
A schematic of your connection to the segments would also help.
Brian.
The schematic which shows 7 segment is RX BOARD and other schematic is of TX and MAIN BOARD. so the schematic i have sent wont relate to port pins of controller schematic i have sent, sorry for not attaching the RX board controller schematic.Hi,
Your code is not complete. We don´t see how "segmentx" is related to a port pin. (and also other signals)
Klaus
yes, i agree that i have set all the segment to '0', because as i told, its my initial test where i only need to know if all the data like "1234" are transmitted to RX board or not. switching the segment will do it once this part is resolved.Hi,
You set all "segment-x = 0". Are you aware that this means you enable all digits at the same time? You need to time multiplex the digits. --> Search for existing forum discussions.
Klaus
sorry.. but did not get this point. different digits..??Hi,
You set "P1=seg;" but you don´t take care about different digits.
In TX-Board you set "seg=P0;" Are you aware that you don´t care about different digits?
I really wonder how you can think your code can work properly.
Klaus
This takes us full circle. The code seems better now but as mentioned as far back as post #2, unless you also tell it which digit is being displayed it cannot possibly work properly. The output of the RX port could be any of the digits or even part of one digit and part of another.
What you need to do is read digit 1, send it, display it as digit 1.
read digit 2, send it, display as digit 2.
read digit 3, send it, display as digit 3.
read digit 4, send it, display as digit 4.
At the moment you read any digit, send it, display it. The 'any digit' could be 1, 2, 3 or 4 or none or a mix of two digits.
Brian.
I´ve seen the schematic, but you need to include thie information into the code. Don´t show us code snippets. (currently we see a TX board snippet and a RX board snippet)The schematic which shows 7 segment is RX BOARD and other schematic is of TX and MAIN BOARD. so the schematic i have sent wont relate to port pins of controller schematic i have sent, sorry for not attaching the RX board controller schematic.
It´s impossible to get "1234" when all DIGITS are ON at the same time.yes, i agree that i have set all the segment to '0', because as i told, its my initial test where i only need to know if all the data like "1234" are transmitted to RX board or not. switching the segment will do it once this part is resolved.
Hi,
I´ve seen the schematic, but you need to include thie information into the code. Don´t show us code snippets. (currently we see a TX board snippet and a RX board snippet)
It´s impossible to get "1234" when all DIGITS are ON at the same time.
Again: read about display multiplexing.
Klaus
Again: your code is not complete, thus I can't see how it shoud read "2" or "3" .... and transmit it via UART.This is what actually should happen according to the code written...
Hi,
Again: your code is not complete, thus I can't see how it shoud read "2" or "3" .... and transmit it via UART.
Provide useful and complete information, otherwise I'm unable to help.
Klaus
We still only have a small part of the code to work from and we do not know how the '373 is connected in relation to the display.
We will however still try to help.
Try this: Disconnect the display and everything else from the TX input port and connect all the port pins to VSS. Tell us what comes out at the RX end.
If it isn't all zeros, tell us what comes out if you disconnect the UART link completely.
Brian.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?