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.
Code:
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 . . .
Code:
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 ?
Code:
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
Bookmarks