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.
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.
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?
Depends on ALL the conditions.... Some may be related... Optimising code is an artform.... Many times you'll come back to a piece of code and say "My god!!! Why did I do that"..
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 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 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
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