Hello world

Solo disponible en BuenasTareas
  • Páginas : 3 (684 palabras )
  • Descarga(s) : 0
  • Publicado : 4 de enero de 2011
Leer documento completo
Vista previa del texto
#include "htc.h"
#include "lcd.h"
#include "delay.h"

#define col0 RB4
#define col1 RB5
#define col2 RB6
#define col3 RB7

#define row0 RB0
#define row1 RB1
#define row2 RB2
#define row3RB3

#define PRESSED 0

char index = 0, op = 0;
char num = 0, result = 0;
char state[2];
char clean;

void LCD_ON()
{
TRISB = 0x00;
}

void LCD_OFF()
{
TRISB = 0xF0;
}cleanLCD(){
LCD_ON();
lcd_clear();
LCD_OFF();
}

void NumberSentToLCD(char n)
{
char c;
SWITCH_LCD_ON();
lcd_goto(index);
c = (char)(n+48);
lcd_putch(c);SWITCH_LCD_OFF();
++index;

}

void showResult(){
num = result;
clean = 1;

for (index = 8; index != 0; ){
NumberSentToLCD((char)(num%10));
num = num/10;
if (num==0) break;
index-=2;}
index = 0;
}

void resolveOp(){
switch(op){
case 5:
break;
case 1:
result = result+num;
break;
case 2:
result = result-num;
break;
case 3:
result = result*num;break;
case 4:
result = result/num;
break;
default:
result = num;
break;
}
}

void checkstatus(char key)
{
switch(key){
case 1:
if(clean){ cleanLCD(); clean = 0;}
if( !(state[0] & 0x80) )
{
NumberSentToLCD(1);
num = num*10 + 1;
state[0] |= 0x80;
}
break;
case 2:
if(clean){ cleanLCD(); clean = 0;}
if( ! (state[0] & 0x40) )
{NumberSentToLCD(2);
num = num*10 + 2;
state[0] |= 0x40;
}
break;
case 3:
if(clean){ cleanLCD(); clean = 0;}
if( ! (state[0] & 0x20) )
{
NumberSentToLCD(3);num = num*10 + 3;
state[0] |= 0x20;
}
break;
case 4:
if( ! (state[0] & 0x10) )
{
cleanLCD();
resolveOp();
showResult();
op = 1;
num = 0;
state[0] |= 0x10;}
break;
case 5:
if(clean){ cleanLCD(); clean = 0;}
if( ! (state[0] & 0x08) )
{
NumberSentToLCD(4);
num = num*10 + 4;
state[0] |= 0x08;
}
break;
case 6:...
tracking img