Could some one give some ideas

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Author
Message
p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#16 Post by p.erasmus » 11 Mar 2009 08:06

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
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

ideasman
Posts: 50
Joined: 01 Mar 2009 23:10

Email

#17 Post by ideasman » 11 Mar 2009 23:32

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

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#18 Post by p.erasmus » 12 Mar 2009 07:27

it is a typo mistake it is p.erasmus@yahoo.de
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

ideasman
Posts: 50
Joined: 01 Mar 2009 23:10

Thanks

#19 Post by ideasman » 25 Mar 2009 12:25

I don't know if you got my email but thanks a lot peter I really appreciate your help.



Cheers

Ideasman

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#20 Post by p.erasmus » 25 Mar 2009 12:48

Ok no problem ,Did you come write is it working on your side
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

ideasman
Posts: 50
Joined: 01 Mar 2009 23:10

Cant get it to work

#21 Post by ideasman » 26 Mar 2009 09:50

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

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#22 Post by p.erasmus » 26 Mar 2009 20:23

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
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

ideasman
Posts: 50
Joined: 01 Mar 2009 23:10

It Works

#23 Post by ideasman » 27 Mar 2009 06:57

It works yea great P.E
Ok were do we go from here how do we get the uart terminal going :D

Also can we make the protcol like the proposed email


Cheers

ideasman

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#24 Post by p.erasmus » 27 Mar 2009 08:44

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.
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

ideasman
Posts: 50
Joined: 01 Mar 2009 23:10

Phase II

#25 Post by ideasman » 29 Mar 2009 09:03

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

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#26 Post by p.erasmus » 29 Mar 2009 10:20

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****************************
ideasman
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
--------------------------------------------------------------

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#27 Post by p.erasmus » 29 Mar 2009 10:43

Also make sure to configure your setup for the Configuration word as XT PLL8 and 80Mhz ,if you do not do this the RC1 led timeing will be incorrect and it might not blink or stay on all the time
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

ideasman
Posts: 50
Joined: 01 Mar 2009 23:10

New example

#28 Post by ideasman » 30 Mar 2009 10:59

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

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#29 Post by p.erasmus » 30 Mar 2009 11:34

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
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

ideasman
Posts: 50
Joined: 01 Mar 2009 23:10

????????

#30 Post by ideasman » 31 Mar 2009 08:16

I dont know whats going on I set the crystal settings, still does what it wants numbers dont correspond to leds only rd 0 and rd 2 turn on now.

?????????

This is so frustrating, if it working on yours it should work on mine.

Ideasman

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”