You are on page 1of 11

#include

#include
#include
#include

<xc.h>
"LCD.h"
"LCD4Bit.h"
<stdint.h>

//__CONFIG ( LVP_OFF & FOSC_HS & BOREN_ON & WDTE_OFF & PWRTE_ON ) ;
struct LCD lcd;
uint8_t x = 0;
uint8_t y = 0;
uint8_t xx = 0;
uint8_t yy = 0;
uint8_t xxx = 0;
uint8_t yyy = 0;
uint8_t z = 0;
uint8_t xuno = 0;
uint8_t yuno = 0;
uint8_t a = 0;
uint8_t b = 0;
uint8_t c = 0;
uint8_t d = 0;
uint8_t e = 0;
uint8_t f = 0;
uint8_t g = 0;
uint8_t h = 0;
uint8_t i = 0;
uint8_t j = 0;
uint8_t k = 0;
uint8_t l = 0;
uint8_t m = 0;
uint8_t n = 0;
uint8_t o = 0;
uint8_t p = 0;
void keypad() {
PORTDbits.RD7=0;
PORTDbits.RD4=1;
if(PORTDbits.RD0==1){
a = 1;
__delay_ms(1);
}
else if (PORTDbits.RD1==1){
e = 1;
__delay_ms(1);
}
else if(PORTDbits.RD2==1){
i = 1;
__delay_ms(1);
}
else if(PORTDbits.RD3==1){
m = 1;

__delay_ms(1);
}
PORTDbits.RD4=0;
PORTDbits.RD5=1;
if(PORTDbits.RD0==1){
b = 1;
__delay_ms(1);
}
else if (PORTDbits.RD1==1){
f = 1;
__delay_ms(1);
}
else if(PORTDbits.RD2==1){
j = 1;
__delay_ms(1);
}
else if(PORTDbits.RD3==1){
n = 1;
__delay_ms(1);
}
PORTDbits.RD5=0;
PORTDbits.RD6=1;
if(PORTDbits.RD0==1){
c = 1;
__delay_ms(1);
}
else if (PORTDbits.RD1==1){
g = 1;
__delay_ms(1);
}
else if(PORTDbits.RD2==1){
k = 1;
__delay_ms(1);
}
else if(PORTDbits.RD3==1){
o = 1;
__delay_ms(1);
}
PORTDbits.RD6=0;
PORTDbits.RD7=1;
if(PORTDbits.RD0==1){
d = 1;
__delay_ms(1);
}
else if (PORTDbits.RD1==1){
h = 1;
__delay_ms(1);
}
else if(PORTDbits.RD2==1){

l = 1;
__delay_ms(1);
}
else if(PORTDbits.RD3==1){
p = 1;
__delay_ms(1);
}
}
void main()
{
TRISD=0x0f;
PORTD=0;
PORTB = 0;
#ifndef _PIC18
ANSELH = 0;
CM1CON0 = 0;
CM2CON0 = 0;
CM2CON1 = 0;
#endif
TRISB = 0;
LCD4Bit_init(&lcd, 4, 5, &PORTB);
LCD_begin(&lcd, 16, 2, LCD_5x8DOTS);
LCD_home(&lcd);
LCD_printString(&lcd, "Calculadora");
while (1){
keypad();
if (n==1 && z==0 && xuno==0)
{
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 0);
x = 0;
xuno=1;
__delay_ms(1000);
}
else if (a==1 && z==0 && xuno==0){
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 1);
x = 1;
xuno=1;
__delay_ms(1000);
}
else if (b==1 && z==0 && xuno==0){
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 2);
x = 2;
xuno=1;
__delay_ms(1000);
}
else if (c==1 && z==0 && xuno==0){
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 3);

x = 3;
xuno=1;
__delay_ms(1000);
}
else if (e==1 && z==0 && xuno==0){
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 4);
x = 4;
xuno=1;
__delay_ms(1000);
}
else if (f==1 && z==0 && xuno==0){
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 5);
x = 5;
xuno=1;
__delay_ms(1000);
}
else if (g==1 && z==0 && xuno==0){
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 6);
x = 6;
xuno=1;
__delay_ms(1000);
}
else if (i==1 && z==0 && xuno==0){
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 7);
x = 7;
xuno=1;
__delay_ms(1000);
}
else if (j==1 && z==0 && xuno==0){
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 8);
x = 8;
xuno=1;
__delay_ms(1000);
}
else if (k==1 && z==0 && xuno==0){
LCD_setCursor(&lcd, 0, 1);
LCD_printUInt(&lcd, 9);
x = 9;
xuno=1;
__delay_ms(1000);
}
else if (n==1 && z==0 && xuno==1)
{
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 0);
xx = 0;
xuno=2;
__delay_ms(1000);
}
else if (a==1 && z==0 && xuno==1){
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 1);
xx = 1;
xuno=2;
__delay_ms(1000);

}
else if (b==1 && z==0 && xuno==1){
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 2);
xx = 2;
xuno=2;
__delay_ms(1000);
}
else if (c==1 && z==0 && xuno==1){
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 3);
xx = 3;
xuno=2;
__delay_ms(1000);
}
else if (e==1 && z==0 && xuno==1){
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 4);
xx = 4;
xuno=2;
__delay_ms(1000);
}
else if (f==1 && z==0 && xuno==1){
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 5);
xx = 5;
xuno=2;
__delay_ms(1000);
}
else if (g==1 && z==0 && xuno==1){
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 6);
xx = 6;
xuno=2;
__delay_ms(1000);
}
else if (i==1 && z==0 && xuno==1){
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 7);
xx = 7;
xuno=2;
__delay_ms(1000);
}
else if (j==1 && z==0 && xuno==1){
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 8);
xx = 8;
xuno=2;
__delay_ms(1000);
}
else if (k==1 && z==0 && xuno==1){
LCD_setCursor(&lcd, 1, 1);
LCD_printUInt(&lcd, 9);
xx = 9;
xuno=2;
__delay_ms(1000);
}
else if (n==1 && z==0 && xuno==2)
{
LCD_setCursor(&lcd, 2, 1);

LCD_printUInt(&lcd, 0);
xxx = 0;
xuno=3;
__delay_ms(1000);
}
else if (a==1 && z==0 && xuno==2){
LCD_setCursor(&lcd, 2, 1);
LCD_printUInt(&lcd, 1);
xxx = 1;
xuno=3;
__delay_ms(1000);
}
else if (b==1 && z==0 && xuno==2){
LCD_setCursor(&lcd, 2, 1);
LCD_printUInt(&lcd, 2);
xxx = 2;
xuno=3;
__delay_ms(1000);
}
else if (c==1 && z==0 && xuno==2){
LCD_setCursor(&lcd, 2, 1);
LCD_printUInt(&lcd, 3);
xxx = 3;
xuno=3;
__delay_ms(1000);
}
else if (e==1 && z==0 && xuno==2){
LCD_setCursor(&lcd, 2, 1);
LCD_printUInt(&lcd, 4);
xxx = 4;
xuno=3;
__delay_ms(1000);
}
else if (f==1 && z==0 && xuno==2){
LCD_setCursor(&lcd, 2, 1);
LCD_printUInt(&lcd, 5);
xxx = 5;
xuno=3;
__delay_ms(1000);
}
else if (g==1 && z==0 && xuno==2){
LCD_setCursor(&lcd, 2, 1);
LCD_printUInt(&lcd, 6);
xxx = 6;
xuno=3;
__delay_ms(1000);
}
else if (i==1 && z==0 && xuno==2){
LCD_setCursor(&lcd, 2, 1);
LCD_printUInt(&lcd, 7);
xxx = 7;
xuno=3;
__delay_ms(1000);
}
else if (j==1 && z==0 && xuno==2){
LCD_setCursor(&lcd, 2, 1);
LCD_printUInt(&lcd, 8);
xxx = 8;
xuno=3;
__delay_ms(1000);

}
else if (k==1 && z==0 && xuno==2){
LCD_setCursor(&lcd, 2, 1);
LCD_printUInt(&lcd, 9);
xxx = 9;
xuno=3;
__delay_ms(1000);
}
else if (d==1 && xuno==3 && yuno==0 && z==0){
LCD_setCursor(&lcd, 3, 1);
LCD_printString(&lcd, "+");
z = 1;
__delay_ms(1000);
d = 0;
}
else if (h==1 && xuno==3 && yuno==0 &&z==0){
LCD_setCursor(&lcd, 3, 1);
LCD_printString(&lcd, "-");
z = 2;
__delay_ms(1000);
h =0;
}
else if (l==1 && xuno==3 && yuno==0 && z==0){
LCD_setCursor(&lcd, 3, 1);
LCD_printString(&lcd, "x");
z = 3;
__delay_ms(1000);
l =0;
}
else if (p==1 && xuno==3 && yuno==0 &&z==0){
LCD_setCursor(&lcd, 3, 1);
LCD_printString(&lcd, "/");
z = 4;
__delay_ms(1000);
p =0;
}
if (n==1 && (z==1 || z==2 || z==3 || z==4) && yuno==0)
{
LCD_setCursor(&lcd, 4, 1);
LCD_printUInt(&lcd, 0);
y = 0;
yuno=1;
__delay_ms(1000);
}
else if (a==1 && (z==1 || z==2 || z==3 || z==4) && yuno==0){
LCD_setCursor(&lcd, 4, 1);
LCD_printUInt(&lcd, 1);
y = 1;
yuno=1;
__delay_ms(1000);
}
else if (b==1 && (z==1 || z==2 || z==3 || z==4) && yuno==0){
LCD_setCursor(&lcd, 4, 1);
LCD_printUInt(&lcd, 2);
y = 2;
yuno=1;
__delay_ms(1000);
}
else if (c==1 && (z==1 || z==2 || z==3 || z==4) && yuno==0){
LCD_setCursor(&lcd, 4, 1);

LCD_printUInt(&lcd, 3);
y = 3;
yuno=1;
__delay_ms(1000);
}
else if (e==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 4, 1);
LCD_printUInt(&lcd, 4);
y = 4;
yuno=1;
__delay_ms(1000);
}
else if (f==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 4, 1);
LCD_printUInt(&lcd, 5);
y = 5;
yuno=1;
__delay_ms(1000);
}
else if (g==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 4, 1);
LCD_printUInt(&lcd, 6);
y = 6;
yuno=1;
__delay_ms(1000);
}
else if (i==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 4, 1);
LCD_printUInt(&lcd, 7);
y = 7;
yuno=1;
__delay_ms(1000);
}
else if (j==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 4, 1);
LCD_printUInt(&lcd, 8);
y = 8;
yuno=1;
__delay_ms(1000);
}
else if (k==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 4, 1);
LCD_printUInt(&lcd, 9);
y = 9;
yuno=1;
__delay_ms(1000);
}
else if (n==1 && (z==1 || z==2 ||
{
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 0);
yy = 0;
yuno=2;
__delay_ms(1000);
}
else if (a==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 1);
yy = 1;
yuno=2;

z==3 || z==4) && yuno==0){

z==3 || z==4) && yuno==0){

z==3 || z==4) && yuno==0){

z==3 || z==4) && yuno==0){

z==3 || z==4) && yuno==0){

z==3 || z==4) && yuno==0){

z==3 || z==4) && yuno==1)

z==3 || z==4) && yuno==1){

__delay_ms(1000);
}
else if (b==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 2);
yy = 2;
yuno=2;
__delay_ms(1000);
}
else if (c==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 3);
yy = 3;
yuno=2;
__delay_ms(1000);
}
else if (e==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 4);
yy = 4;
yuno=2;
__delay_ms(1000);
}
else if (f==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 5);
yy = 5;
yuno=2;
__delay_ms(1000);
}
else if (g==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 6);
yy = 6;
yuno=2;
__delay_ms(1000);
}
else if (i==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 7);
yy = 7;
yuno=2;
__delay_ms(1000);
}
else if (j==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 8);
yy = 8;
yuno=2;
__delay_ms(1000);
}
else if (k==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 5, 1);
LCD_printUInt(&lcd, 9);
yy = 9;
yuno=2;
__delay_ms(1000);
}
else if (n==1 && (z==1 || z==2 ||
{

z==3 || z==4) && yuno==1){

z==3 || z==4) && yuno==1){

z==3 || z==4) && yuno==1){

z==3 || z==4) && yuno==1){

z==3 || z==4) && yuno==1){

z==3 || z==4) && yuno==1){

z==3 || z==4) && yuno==1){

z==3 || z==4) && yuno==1){

z==3 || z==4) && yuno==2)

LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 0);
yyy = 0;
yuno=3;
__delay_ms(1000);
}
else if (a==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 1);
yyy = 1;
yuno=3;
__delay_ms(1000);
}
else if (b==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 2);
yyy = 2;
yuno=3;
__delay_ms(1000);
}
else if (c==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 3);
yyy = 3;
yuno=3;
__delay_ms(1000);
}
else if (e==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 4);
yyy = 4;
yuno=3;
__delay_ms(1000);
}
else if (f==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 5);
yyy = 5;
yuno=3;
__delay_ms(1000);
}
else if (g==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 6);
yyy = 6;
yuno=3;
__delay_ms(1000);
}
else if (i==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 7);
yyy = 7;
yuno=3;
__delay_ms(1000);
}
else if (j==1 && (z==1 || z==2 ||
LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 8);
yyy = 8;
yuno=3;

z==3 || z==4) && yuno==2){

z==3 || z==4) && yuno==2){

z==3 || z==4) && yuno==2){

z==3 || z==4) && yuno==2){

z==3 || z==4) && yuno==2){

z==3 || z==4) && yuno==2){

z==3 || z==4) && yuno==2){

z==3 || z==4) && yuno==2){

b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
}

__delay_ms(1000);
}
else if (k==1 && (z==1 || z==2 || z==3 || z==4) && yuno==2){
LCD_setCursor(&lcd, 6, 1);
LCD_printUInt(&lcd, 9);
yyy = 9;
yuno=3;
__delay_ms(1000);
}
else if (o==1 && z==1 && yuno==3 && xuno==3){
LCD_setCursor(&lcd, 7, 1);
LCD_printString(&lcd, "=");
LCD_setCursor(&lcd, 8,1);
LCD_printUInt(&lcd, (x*100+xx*10+xxx)+(y*100+yy*10+yyy));
}
else if (o==1 && z==2 && yuno==3 && xuno==3){
LCD_setCursor(&lcd, 7, 1);
LCD_printString(&lcd, "=");
LCD_setCursor(&lcd, 8,1);
LCD_printUInt(&lcd, (x*100+xx*10+xxx)-(y*100+yy*10+yyy));
}
else if (o==1 && z==3 && yuno==3 && xuno==3){
LCD_setCursor(&lcd, 7, 1);
LCD_printString(&lcd, "=");
LCD_setCursor(&lcd, 8,1);
LCD_printUInt(&lcd, (x*100+xx*10+xxx)*(y*100+yy*10+yyy));
}
else if (o==1 && z==4 && yuno==3 && xuno==3){
LCD_setCursor(&lcd, 7, 1);
LCD_printString(&lcd, "=");
LCD_setCursor(&lcd, 8,1);
LCD_printUInt(&lcd, (x*100+xx*10+xxx)/(y*100+yy*10+yyy));
}
a =0;
=0;
=0;
=0;
=0;
=0;
=0;
=0;
=0;
=0;
=0;
=0;
=0;
=0;
=0;
=0;
}

You might also like