Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18F and USART

Status
Not open for further replies.
I tested all the hardware as below:

First I shorted pins 2 and 3 of the USB to Serial cable (i.e. RX and TX). I then used PuTTY to check if data is being transmitted and received correctly. This way i confirmed that the cable and the driver were in order.

I then shorted pins 11 and 12 of the MAX232 IC, hence bypassing the PIC. Again I used PuTTY to test for correct data and it also worked.

The rest was to check if either the PIC was damaged or the coding was incorrect. I changed the PIC and all ok, which concluded that the problem was the code.

To be honest I just copied and paste the PIC config from a forum, which was as follow:

#pragma config FOSC = HS // 20MHz Crystal, (HS oscillator)
#pragma config PBADEN = OFF // PORTB<4:0> pins are configured as digital I/O on Reset
#pragma config WDT = OFF // watch dog timer off
#pragma config LVP = OFF // Low voltage program off

Tomorrow I will go through the config setting from MPLAB to understand them better.

Again thanks for your help and patient :)
 
The rest was to check if either the PIC was damaged or the coding was incorrect. I changed the PIC and all ok, which concluded that the problem was the code.

I think your problem was a short on one of the micro pins on Tx or Rx....( I have also done this!!)

At least your up and running.... Any questions and we'l try and answer them...
 
Hi again,

The reason I wanted to use USART is to interface Visual Studio with the PIC. Now lest say i have 20 buttons on VS, does that mean I have to do 20 if conditions?

Eg:
Code:
If(data == 'a')
{
Turn motor 1 clockwise
}
If(data == 'b')
{
Turn motor 1 counter clockwise
}
If(data == 'c')
{
Turn LED on
}
............................
............................


Or is there a neater/more efficient way to do this?
 
probably better to use CASE/SWITCH?? but i dont know for sure and like mr Ian says depends on the data.
but am a noob with C
 
At 9600 baud, a new symbol can arrive only every 10 ms or so. Therefore, you have plenty of time amd it isn't worth working on code optimization.
 
sorry i am rubbish at maths its my worst subject at school, could you explain how you get a symbol every 10ms at 9600 baud. i tried working it out and only got 1.2ms??? where did i go wrong :oops: sorry for the stupid question
what i did was take 9600 bit per second and divide that by 8 as i assume a character is 8 bits (byte) then divide that by 1000 and i got 1.2
i spose in the real world you also have to add the start and stop bit time? as well
LG
 
sorry i am rubbish at maths its my worst subject at school, could you explain how you get a symbol every 10ms at 9600 baud. i tried working it out and only got 1.2ms??? where did i go wrong :oops: sorry for the stupid question
what i did was take 9600 bit per second and divide that by 8 as i assume a character is 8 bits (byte) then divide that by 1000 and i got 1.2
i spose in the real world you also have to add the start and stop bit time? as well
LG

There are also start and stop bits, but you're right, it's around 1 ms. My math was wrong. Still very slow.
 
thanks for that, i thought i had messed up!! as maths is not my strong point and i like to note down stuff like this! still gets me how much a micro can do in 1ms!! amazing stuff
 
thanks for that, i thought i had messed up!! as maths is not my strong point and i like to note down stuff like this! still gets me how much a micro can do in 1ms!! amazing stuff
hi LG,
Allow, for most RS232 serial applications, 1 start bit, 8 data bits, 1 stop bit ie: 10 bits per character.
So 9600 baud/10 = ~ 960 characters/second
E
 
thanks for that, i thought i had messed up!! as maths is not my strong point and i like to note down stuff like this! still gets me how much a micro can do in 1ms!! amazing stuff

Math was always my strongest ... :)

My PIC uses UART to talk to the USB adapter and it does so at 2,000,000 baud.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top