|
ME Labs, Inc. 719-520-5323 |
|
|
|
ME Labs, Inc. | 1-719-520-5323 | Example Program - BCD.pbpPICBASIC PRO program to demonstrate conversion to and from BCD.' Name : BCD.pbp
' Compiler : PICBASIC PRO Compiler 2.6
' Assembler : PM or MPASM
' Target PIC : 16F, 18F types
' Hardware : Non specific
' Oscillator : internal or external
' Keywords : SEROUT2
' Description : PICBASIC PRO program to demonstrate conversion
' to and from BCD.
'
pinout VAR PORTC.6 ' Define serial output pin
pinin VAR PORTC.7 ' Define serial input pin
bcdin VAR BYTE ' BCD data in
bcdout VAR BYTE ' BCD data out
binhold VAR BYTE ' Binary data
addamt CON 12 ' Set value to add
ADCON1 = 7 ' Set ports A and E to digital
mainloop:
Serout2 pinout,396,["Enter 2-digit decimal number:",10,13] ' Send prompt to user
Serin2 pinin,396,[HEX2 bcdin] ' Receive 2 characters as BCD data with the HEX2 modifier
binhold = ((bcdin >> 4) * 10) + (bcdin & $0f) ' Convert bcdin to binary
binhold = binhold + addamt ' Add addamt to binary value
If binhold>99 Then errmess ' Make sure result is less than 100
bcdout = ((binhold / 10) << 4) + (binhold // 10) ' Convert binhold to BCD
' Send data as BCD with the HEX2 modifier
Serout2 pinout,396,[HEX2 bcdin, " + ", DEC addamt, " = ", HEX2 bcdout,10,13]
Goto mainloop ' Do it forever
errmess: ' Send error message
Serout2 pinout,396,[10,13,"ERROR: Result greater than 99",10,13,10,13]
Goto mainloop ' Begin again
End
Download the program file. |
|
Copyright 2019 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|