Could some one give some ideas
Mail me your project with a clear description of what you want to do in code and also a schematic or drawing of the Uarts talking or forming your serial communication,I can not work on it now as I said before I am in Germany but could help and clear or make you code work and you can learn from it ,I can do this on sunday when I am at home.
yes you can use data in a byte to write to 1 pin but then you need to mask out the data you want from the byte and that you do with "and"
,shift operations look in the compiler manual for bit or logical operators
p,erasmus@yahoo.de
yes you can use data in a byte to write to 1 pin but then you need to mask out the data you want from the byte and that you do with "and"
,shift operations look in the compiler manual for bit or logical operators
p,erasmus@yahoo.de
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
In Australia we cannot use emails with commas in them you have p,erasmus@yahoo.de is it p.erasmus@yahoo.de or send to
chris.ruth77@optusnet.com.au and ill pick up your address.
Cheers
Ideasman
chris.ruth77@optusnet.com.au and ill pick up your address.
Cheers
Ideasman
it is a typo mistake it is p.erasmus@yahoo.de
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
Cant get it to work
Sorry i have been away now I got some time to play.
It compiled but it does not work or maybe the string I am sending is wrong, i don't know.
Can you tell me some instructions to get it going
so far:
rf3 = tx rf2 =rx
and Im using the uart terminal in microbasic sending #481632
ideasman
It compiled but it does not work or maybe the string I am sending is wrong, i don't know.
Can you tell me some instructions to get it going
so far:
rf3 = tx rf2 =rx
and Im using the uart terminal in microbasic sending #481632
ideasman
you need to program your board with the code I send you and then bridge terminal 2 and 3 of your RS232 ConnectorA run the code and you will see the leds come on one by one .
this code shows you how the Data bytes are send from the Tx of UART1 and received by UART1 Rx and then decoded and switch the led on according to the number in the byte array .
Then you have to use these principlas I showed in the code to write your code to do what you want it to do.
Firts run my code and get that working and then we try your code or write code that will do the job for you
this code shows you how the Data bytes are send from the Tx of UART1 and received by UART1 Rx and then decoded and switch the led on according to the number in the byte array .
Then you have to use these principlas I showed in the code to write your code to do what you want it to do.
Firts run my code and get that working and then we try your code or write code that will do the job for you
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
Yes we can make a protocol ,Now We will do code that sends the data to the UART terminal in the IDE and we will send data from the Uart terminal to the Pic.
from you I need an schematic of your circuits or Relay and the information what you want to do.then I will help you but you must write the code because if I write the code you have learned nothing.
from you I need an schematic of your circuits or Relay and the information what you want to do.then I will help you but you must write the code because if I write the code you have learned nothing.
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
Phase II
InitController() 'set up the controller (function call)
while True
for count = 0 To 4 step 1
myArray[count] = Uart1_Read_Char() 'read the data buffer
'
next count
while Uart1_Data_Ready = 1 ' wait for the receive flag
'nop
wend
'delay_ms(100) 'for demo wait a while before sending next byte
count = 0 ' clear the send counter for next transmission
if myArray[0] = 35 then 'Command value = # = decimal 35
LATB = myArray[1]
delay_ms(200) 'read the data in receive array and
LATB = myArray[2] 'diplay on port B
delay_ms(200)
LATB = myArray[3] ' notice only 1 led on at a time
delay_ms(200) ' correpponding to the different relays you want
LATB = myArray[4] ' you want to switch on
delay_ms(200)
else
LATC.01 = 1
delay_ms(300) 'if the wrong command received flash RC1
LATC.01 = 0
delay_ms(300)
end if
LATB = 0 'Clear Port B and start again
wend
end.
What I am trying to do is get your version going with the uart, as the count is going through the array it is erasing the values so when it gets to the if myArray[0] = 35 it sees nothing in the array. Why is this happening.
Also how do we get it to hold a value after the buffer has been flushed eg leaving an led on until we tell it to turn off. I know im skipping ahead but I would like a head start.
Thanks
Ideasman
while True
for count = 0 To 4 step 1
myArray[count] = Uart1_Read_Char() 'read the data buffer
'
next count
while Uart1_Data_Ready = 1 ' wait for the receive flag
'nop
wend
'delay_ms(100) 'for demo wait a while before sending next byte
count = 0 ' clear the send counter for next transmission
if myArray[0] = 35 then 'Command value = # = decimal 35
LATB = myArray[1]
delay_ms(200) 'read the data in receive array and
LATB = myArray[2] 'diplay on port B
delay_ms(200)
LATB = myArray[3] ' notice only 1 led on at a time
delay_ms(200) ' correpponding to the different relays you want
LATB = myArray[4] ' you want to switch on
delay_ms(200)
else
LATC.01 = 1
delay_ms(300) 'if the wrong command received flash RC1
LATC.01 = 0
delay_ms(300)
end if
LATB = 0 'Clear Port B and start again
wend
end.
What I am trying to do is get your version going with the uart, as the count is going through the array it is erasing the values so when it gets to the if myArray[0] = 35 it sees nothing in the array. Why is this happening.
Also how do we get it to hold a value after the buffer has been flushed eg leaving an led on until we tell it to turn off. I know im skipping ahead but I would like a head start.
Thanks
Ideasman
Code: Select all
'************************************************************
program USART_RX_TX
'************************************************************
'***************************************
'Array holds the Data received from Pc
'***************************************
Dim Data as word[8]
Dim RxCounter as byte
Dim TX_ready as byte
Dim LED_Display_ready as byte
'*************************************************************
'Timer 1 Interrupt (Toggle Run LED)
'*************************************************************
sub procedure Timer1Int org $1A
IFS0 = IFS0 and $FFF7
LATC.01 = LATC.01 xor 1
end sub
'*************************************************************
' Initializes the Microcontroller
'*************************************************************
sub procedure InitController ()
TRISC.01 = 0 'Pin RC1 as output for led
TRISC.04 = 0 ' Led shows Data received
TRISD = 0 'Display the value in the bytes on PORTD
IEC0.03 = 1 'T1 INT On
IPC0.14 = 0 'T1 Ip 4
IPC0.13 = 0
IPC0.12 = 1
IFS0.03 = 0 'T1IF Clear
PR1 = 25000 'set Time out at 250mSec
T1CON = $A030 'Timer1 On - Prescaler 256
Uart1_Init(9600) 'Set baud rate
end sub
'*************************************************************
'**************************************************************
'Main application code
'**************************************************************
main:
InitController() 'call the init procedure
while True
'*******************************
'Receive the Data array
'********************************
if (Uart1_Data_Ready() <> 0) Then
for RxCounter = 0 To 3 Step 1
LATC.04 = LATC.04 xor 1
Data[RxCounter] = Uart1_Read_Char()
while (Uart1_Data_Ready()<> 1)
wend
next RxCounter
TX_ready = 1
end if
'******************************
'Process the Data
'******************************
if(TX_ready <>0) Then
for RxCounter = 0 To 3 Step 1
Uart1_Write_Char (Data[RxCounter])
delay_ms(1)
next RxCounter
TX_ready = 0
LED_Display_ready = 1
end if
'*********************************
'Display the binary number in byte
'on PORTD Low Byte
'*********************************
If (LED_Display_ready <>0) Then
for RxCounter = 0 To 3 Step 1
LATD = Data[RxCounter]- 48 'Terminl send ASCII to get a number
delay_ms(3000) 'between 0-9 we subtract 48
next RxCounter ' ASCII 52 - 48 = dec 4
LED_Display_ready = 0
LATD = 0
end if
wend
end.
'************************EOF****************************
some where there is a misunderstanding Let us start from the beginning .
the code is working perfectly with me.
The above code will receive 3 bytes as data and 1 byte as the end of data command which then triggers the next loop to send back to your UART terminal the data it has received from your Terminal.
after it has send the data to your terminal back it will flash the leds on PORTD to the number in the data array.
Becareful with the terminal program as in my view it sends ASCII characters for the number you want to send there for if you send a number 2 the PIC receives dec 50 or hex 0x32 see in the code how I take the number to a decimal number again.
the second point is do not send a string of numbers send 1 number at a time from the terminal program
example send 2 then see led RC4 toggle telling you the PIC received it then send numder 5 see RC4 toggle again then send 6 RC4 again toggle
then send the fourth number and you will see the firts 3 numbers in the terminal program.
RC 1 is interrupt driven and will flash continiously to indicate thet the controller is running
In the Terminal program you must select ASCII in the FORMAT and nothing else except the COM port and the Baudrate .
Once you have this working we will go to the next step by sending a string of hex and or Dec numbers
Note send only numbers between 0-9 at a time as if you send higher numbers then we must combine the bytes to get the numbers and therefore we will then use the string functions ,now we firts want to see that your board and terminal program is working ,
next we will save the data and we will work with strings .
Hope you come right with thus
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
New example
Ok I have loaded your example, compiled but, no matter what number I send in ascii 0-9 pins rd 8 & rd9 are the only leds that will turn on and then off which is what the timer is doing. Also can you explain the 80mhz, do I have to change the crystal I only have a 10mhz one. The setting you require is in the new project file right cause I always use the default setting and most things work.
sub procedure Timer1Int org $1A
IFS0 = IFS0 and $FFF7
LATC.01 = LATC.01 xor 1
end sub
IEC0.03 = 1 'T1 INT On
IPC0.14 = 0 'T1 Ip 4
IPC0.13 = 0
IPC0.12 = 1
IFS0.03 = 0 'T1IF Clear
PR1 = 25000 'set Time out at 250mSec
T1CON = $A030 'Timer1 On - Prescaler 256
Whats exactly going on here with this code for you have changed your format?
ideasman
sub procedure Timer1Int org $1A
IFS0 = IFS0 and $FFF7
LATC.01 = LATC.01 xor 1
end sub
IEC0.03 = 1 'T1 INT On
IPC0.14 = 0 'T1 Ip 4
IPC0.13 = 0
IPC0.12 = 1
IFS0.03 = 0 'T1IF Clear
PR1 = 25000 'set Time out at 250mSec
T1CON = $A030 'Timer1 On - Prescaler 256
Whats exactly going on here with this code for you have changed your format?
ideasman
This code run perfectly with me over the UART tool
nothing is changed the loops to receicve are the same ,then it has a loop to send back the data to the UART tool which it has received.then the timer interrupt just blik a led to show the the microcontroller is running.
No you do not have to change the crystal go into your project ->edit project and select XT PLL 8 and onthe top you will see a place where the
speed is given in a number writin 080.000000 then you have it
somewhere on your board or project something is wrong as I said this code runs on my dspICPro4 board
nothing is changed the loops to receicve are the same ,then it has a loop to send back the data to the UART tool which it has received.then the timer interrupt just blik a led to show the the microcontroller is running.
No you do not have to change the crystal go into your project ->edit project and select XT PLL 8 and onthe top you will see a place where the
speed is given in a number writin 080.000000 then you have it
somewhere on your board or project something is wrong as I said this code runs on my dspICPro4 board
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------