habe mir dank eurer Hilfe mal was zum testen gebastelt um aus einer 2 Stelligen numeric nach 2 x BCD aufzulösen und auf dem LCD anzuzeigen.
Mir hat es für das Verständnis weiter geholfen.
Code:
'Demonstration zur Wandlung von 2 Stelligen Zahlen nach BCD
'----------------------------------------------------------
$regfile = "m8def.dat" 'ATmega8-Deklarationen
$crystal = 3686400 'Taktfrequenz: 3,6864 MHz
$baud = 9600
On Urxc Onrxd 'Interrupt-Routine setzen
Enable Urxc 'Interrupt URXC einschalten
Enable Interrupts 'Interrupts global zulassen
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portd.5 , Rs = Portd.4
Config Lcdbus = 4
Cls
Dim A As Byte
Dim B As Byte
Dim C As Byte
Dim D As Byte
Dim E As Byte
Dim F As Byte
Dim G As Byte
Dim H As Byte
Dim I As Byte
Dim L As Byte
Dim Z As Byte
Dim Y As Byte
Dim U As Byte
'Dim V As String * 4
Z = 96
'----------------------------------------------------------
Main:
Cls
Y = Makebcd(z)
L = Y And &B0000_1111 'Mask To Get Only Low Nibble Of Byte , Store As C
H = Y And &B1111_0000 'Mask To Get Only High Nibble Of Byte
Shift H , Right , 4 'Shift High Nibble To Low Nibble Position , Store As H
A = L And &B0000_0001 'Low Byte zerlegen in BCD Code
If A >= 1 Then A = 1 'abfrage
B = L And &B0000_0010
If B >= 1 Then B = 1
C = L And &B0000_0100
If C >= 1 Then C = 1
D = L And &B0000_1000
If D >= 1 Then D = 1
E = H And &B0000_0001
If E >= 1 Then E = 1
F = H And &B0000_0010
If F >= 1 Then F = 1
G = H And &B0000_0100
If G >= 1 Then G = 1
I = H And &B0000_1000
If I >= 1 Then I = 1
Locate 1 , 1
Lcd Bcd(h) ; " High" 'Ausgabe des high Byte
Locate 1 , 10
Lcd I ; " " ; G ; " " ; F ; " " ; E 'Ausgabe des BCD codes
Locate 3 , 1
Lcd Bcd(l) ; " Low "
Locate 3 , 10
Lcd D ; " " ; C ; " " ; B ; " " ; A
'BCD High = 8 4 2 1
'variable = I G F E
'BCD Low = 8 4 2 1
'variable = D C B A
Wait 1
Goto Main
Onrxd:
U = Udr 'Byte aus der UART auslesen
Udr = U 'Byte als Echo zurückgeben
Z = U
Return
Lesezeichen