Serial comms PIC to PC

Art

Joined Sep 10, 2007
806
He means if the value you get from the ADC is 10 bit, it is larger value
than can be sent with one byte, so you need to send it in two bytes.
 

Thread Starter

fyee

Joined Mar 7, 2010
16
The program for the weight sensor to show on LCD.
So, where should I add the program for USART?
 
Last edited:

symqwerty

Joined Feb 22, 2010
31
after TRISB = 0, put
Rich (BB code):
USART_Init(9600);   // baud rate 9600kbps
delay_ms(20);        // relax
after temp_res...
Rich (BB code):
Usart_Write(ADRESH);          //send result [15:8]
Usart_Write(ADRESL);          // [7:0]

//pls replace ADRESH and ADRESL with MSB and LSB of temp_res respectively...
 

Thread Starter

fyee

Joined Mar 7, 2010
16
after TRISB = 0, put
Rich (BB code):
USART_Init(9600);   // baud rate 9600kbps
There is an error here,can't be compiled. Should I do any changes on the USART Terminal or connect it to a serial port?

Btw, how do I do the calculation on PC? Can give some hint?
 
Last edited:

symqwerty

Joined Feb 22, 2010
31
What version of MikroC compiler you use? pls check it because if you are using newer version, you have different function name, such as "UART1_init(9600)." Since this is built-in function/routine, and when you have trouble with it, pls help yourself by reading mikroC manual -> just go to help in menubar.
http://www.mikroe.com/en/compilers/mikroc/pic/builtin.htm

If the program works, then, try to use HTPERTERMINAL first to check the output from PIC and if correct, you can start programming (PC). You can use Excel, VB.NET, C++ or C#..
 

Thread Starter

fyee

Joined Mar 7, 2010
16
Rich (BB code):
Usart_Write(ADRESH);          //send result [15:8]
Usart_Write(ADRESL);          // [7:0]

//pls replace ADRESH and ADRESL with MSB and LSB of temp_res respectively...

I don't understand the coding here. Mind to explain?
Thanks so much. I hope this can be solved asap as I'm running out of time to submission date for project.
 

symqwerty

Joined Feb 22, 2010
31
I don't understand the coding here. Mind to explain?
Thanks so much. I hope this can be solved asap as I'm running out of time to submission date for project.
This is the way to send data out from PIC using UART. ADRESH and ADRESL are two registers that hold digital value of ADC conversion. So, this code will send 8-bit of ADRESH through UART followed by ADRESL..your PC will receive 2 bytes of data..
 

Thread Starter

fyee

Joined Mar 7, 2010
16
the coding can be compiled but it shows all the alien words on my LCD.
if I remove the 2 lines below, the program works well.

Usart_Write(ADRESH); //send result [15:8]
Usart_Write(ADRESL); // [7:0]

why does it happen?
 

retched

Joined Dec 5, 2009
5,207
The Usart_Write command is sending the contents of the (ADRESH) and(ADRESL) registers to the LCD. (Or whatever you have connected via Usart.

ADRESH contain the high bits and the ADRESL are the LOW bits of the byte.
 

Markd77

Joined Sep 7, 2009
2,806
You will get alien words if you send numeric data to something that is expecting ASCII. for example if you send D'123' you will see "{" on the display. Is that the problem?
 

Thread Starter

fyee

Joined Mar 7, 2010
16
Not really.
It could work in the program I wrote for few seconds, and would show alien words after that. I have no ideas why would that happen.
 

Markd77

Joined Sep 7, 2009
2,806
Could you let us know more details of the setup? A photo of the LCD might also help in diagnosing it.
If it works for a while, maybe the baud rate is not quite right. Setting the stop bit length to 2 bits on sender and reciever might possibly help in that case.
 
Top