PDA

View Full Version : please who can help me for sample code



jasem700
- 10th February 2009, 19:15
hello my friend

please who can help me for sample code to create serial communication between 16f84A to 16f84A when using SEROUT/SERIN
I want to send a decimal number (0000 to 9999) from one PIC to the other where it's display it on 7 segment display 4 digit as shown in pictur attached

http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3069&d=1230391117
and thankyou very much

Archangel
- 10th February 2009, 23:01
I will help you but I will not do it for you, why? Because you learn nothing that way.
So sit down and figure out what you want the chips to do and in what order, make a block diagram and that is how to start.

Archangel
- 13th February 2009, 16:57
Where did you go ? This is what I was talking about:
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3197&stc=1&d=1234544097

nemesis
- 14th February 2009, 14:02
You should buy the book "Programming PIC Microcontrollers With PicBasic" By Chuck Hellebuyck. There are examples of pic to pic and driving 7 segment displays. With all the explanation behind it.

Good Luck!

-Nemesis

jasem700
- 16th February 2009, 23:18
thanks for JOE please excuse me i am begining in programtion of pic and my english is litelle

i want to send number 4 digit like 1234 or 2564 or 2358 from pic 1684a to anoder 1684a where it's display it on 7 segment display 4 like your diagram
if you dont understand me i try to explain to you

Archangel
- 17th February 2009, 08:22
Hi jasem700,
I understand what you want to do, and it's not too tough. Look at the block diagram and take a swing at what commands you need to use to acheive your goal. For instance, how might you receive some data? You have choices of serin, serin2, hserin, i2cread, . . . pick one!
then you need a place to store that information, a variable. You are storing a 4 digit number, correct? so the number will not be larger than 9999, and 9999 will not fit into a byte as a byte only holds up to 255 so the next larger variable is a word which will hold up to 65535.
So in the paragraph above we know we have to store a word so here is how to do it:
MyVar VAR WORD , you can call the variable almost anything like HOT_COFFEE or WHISKEY make it something meaningful to you, the compiler doesn't care.

let's try serin as a way to get the number in.


include"modedefs.bas"
main:
SERIN PortA.0,T9600,MyVar
GOTO main
end

the code above will receive your number and loop over and over, pretty useless as is,
you need more code to make it do what you want, but it does get the information.
Now that you have captured the number you need to isolate the digits, and again you need a place to store those numbers, yep you guessed it variables again, and they will be bytes as they are smaller than 255 ,so let's name them digit, so . . .


include"modedefs.bas"
digit1 var byte
digit2 var byte
digit3 var byte
digit4 var byte
MyVar VAR WORD
main:
SERIN PortA.0,T9600,MyVar
GOTO main
end

The DIG command isolates which digit you store in the variable like so
myvar = 1298
digit1 = MyVar DIG1
digit2 = MyVar DIG2
digit3 = MyVar DIG3
digit4 = MyVar DIG4
Now you have your number stored in MyVar and have them isolated as individual digits.
Do you follow so far ?


include"modedefs.bas"
digit1 var byte
digit2 var byte
digit3 var byte
digit4 var byte
MyVar VAR WORD
main:
SERIN PortA.0,T9600,MyVar
digit1 = MyVar DIG1
digit2 = MyVar DIG2
digit3 = MyVar DIG3
digit4 = MyVar DIG4
GOTO main
end

As you see, building blocks add code as you need it and the large program begins to materialize.
Next you have to figure out which port will output your 7 segment display will use, each segment will
have a port address. Lay out the port in a binary fashion where 1 is on and 0 is off and you can figure out what to
energise to display the number you want to display. Use a lookup table to assign the port output to achieve this and store in more variables. Let's call those variables Display, so Display1 var BYTE . . . and you would write it like
LOOKDOWN2 digit1,[ your number for zero, yournumberforone, . . . ],display1
this will give you the appropriate LED pattern for the number in digit1 variable ready to display.
then to display you would simply make a statement like portB = display1

jasem700
- 22nd February 2009, 20:41
thank you very much Mr joe i have read your reply and I try to apply what you write to me thanks please if you want tell me your email adress please I want to email you ok thannks