Last active
August 17, 2017 12:45
-
-
Save urmil0071/f991331d2557638f43688e2336fd5589 to your computer and use it in GitHub Desktop.
Write program to add BCD 67 and 25 and show result (92) at DP0,DP1 of Line-1 of LCD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5); | |
void setup() | |
{ | |
byte x1=0x67; | |
byte x2=0x25; | |
lcd.begin(16,2); | |
lcd.clear(); | |
lcd.setCursor(5,1); | |
byte x1low=x1>>0; | |
x1low=x1low&0x0F; /// lower 4 bits of x1 | |
byte x2low=x2>>0; | |
x2low=x2low&0x0F;/// lower 4 bit of x2 | |
bool HalfCarry=bitRead(x1low+x2low,4); | |
int z=x1+x2; | |
bool FullCarry=bitRead(z,8); | |
byte zu=z>>4; | |
zu=zu&0x0F; ///upper 4 bits of z | |
byte zl=z>>0; | |
zl=zl&0x0F; ///LOWER 4 bits of z | |
if(zl>9) ///if lower 4 bit is greater than 9, add 0x06 | |
{ | |
z=z+0x06; | |
} | |
if (zu>9) ///if upper 4 bit is greater than 9, add 0x60 | |
{ | |
z=z+0x60; | |
} | |
if (HalfCarry == 1) /// if half Carry present, Add 0x06 | |
{ | |
z=z+0x06; | |
} | |
if (FullCarry== 1) /// if full Carry present, Add 0x60 | |
{ | |
z=z+0x60; | |
} | |
lcd.print(z,HEX); | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment