Los feos del peru

Solo disponible en BuenasTareas
  • Páginas : 5 (1021 palabras )
  • Descarga(s) : 0
  • Publicado : 5 de junio de 2011
Leer documento completo
Vista previa del texto
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <HD44780/lcd_lib.h>
#include <TWI/TWI.c>
#include <inttypes.h>

#define KB_PORT_OUT PORTA
#define KB_PORT_IN PINA

unsigned char upperNibble,keyCode,tecla,i;
unsigned int numero,frec;
volatile unsigned char t_en,A,B,C,D,digito;

voidTWI_start(void);
void TWI_repeated_start(void);
void TWI_init_master(void);
void TWI_write_address(unsigned char);
void TWI_read_address(unsigned char);
void TWI_write_data(unsigned char);
void TWI_read_data(void);
void TWI_stop(void);

//__STREAM LCD
static int LCDsendstream(char c, FILE *stream);
static FILE lcd_str = FDEV_SETUP_STREAM(LCDsendstream, NULL, _FDEV_SETUP_WRITE);
static intLCDsendstream(char c , FILE *stream)
{
LCDsendChar(c);
return 0;
}

ISR(TIMER0_COMP_vect)
{
upperNibble = 0xff;

for(i=0; i<4; i++)
{
_delay_ms(1);
KB_PORT_OUT = ~(0x01 << i);
_delay_ms(1);
upperNibble = KB_PORT_IN | 0x0f;

if (upperNibble != 0xff)
{
_delay_ms(20);
//Evitar Rebotes
upperNibble = KB_PORT_IN | 0x0f;
if(upperNibble == 0xff) goto OUT;

keyCode= (upperNibble & 0xf0) | (0x0f & ~(0x01 << i));
t_en=1;

while (upperNibble != 0xff)
upperNibble = KB_PORT_IN | 0x0f;

_delay_ms(20);
//Evitar Rebote

switch (keyCode)
{
case (0x7d): tecla = 0;
break;
case (0xee): tecla = 1;
break;
case (0xed): tecla = 2;
break;
case (0xeb): tecla = 3;
break;
case (0xde): tecla = 4;
break;
case (0xdd): tecla =5;
break;
case (0xdb): tecla = 6;
break;
case (0xbe): tecla = 7;
break;
case (0xbd): tecla = 8;
break;
case (0xbb): tecla = 9;
break;
case (0x7e): tecla = 10;
break;
case (0x7b): tecla = 11;
break;
case (0xe7): tecla = 12;
break;
case (0xd7): tecla = 13;
break;
case (0xb7): tecla = 14;
break;
case (0x77): tecla = 15;
break;
default : t_en = 0;
}OUT:;
}
}

}

int main(void)
{
DDRB=0B11110111;
DDRA=0x0F;
//high nibble for output(columns) low for input(rows);
PORTA=0xFF;
//enable internal pullups
TCCR0=0B00001101;
//Normal
//CTC
//CLK/1024
OCR0=155;
//Timer a 20ms
TIMSK=0B00000010;
//Habilito Interrupción Compare Match
TWI_init_master();
//Inicio TWI
LCDinit();
LCDclr();
stdout=&lcd_str;printf("Two Wire");
LCDGotoXY(5,1);
printf("Interface");
_delay_ms(1500);
LCDclr();
LCDhome();
printf("VICODG");
LCDGotoXY(3,1);
printf("BLOGSPOT.COM");
_delay_ms(1500);
LCDclr();
LCDhome();
sei();
while(1)
{
if (t_en==1)
{
t_en=0;
switch (tecla)
{
case 10:
LCDclr();
LCDhome();
printf("Funcion *");
break;
case 11:
LCDclr();LCDhome();
printf("Funcion #");
break;
case 12:
switch (digito)
{
case 1:
numero=A;
break;
case 2:
numero=A*10+B;
break;
case 3:
numero=A*100+B*10+C;
break;
case 4:
numero=A*1000+B*100+C*10+D;
break;
default:
numero=A*1000+B*100+C*10+D;
break;
}
digito=5;
LCDGotoXY(0,1);printf("%d",numero);
LCDGotoXY(6,1);
printf("Hercios");
A=0;B=0;C=0;D=0;numero=0;
break;
case 13:
TWI_start();
TWI_write_address(address+write);
TWI_write_data(write_data);
TWI_stop();
printf("Enviando Mensaje");
break;
case 14:
LCDclr();
LCDhome();
printf("Funcion C");
break;
case 15:
LCDclr();
LCDhome();
printf("FRECUENCIA: ");A=0;B=0;C=0;D=0;numero=0;digito=0;
break;
default:
digito++;
switch (digito)
{
case 1:
A=tecla;
break;
case 2:
B=tecla;
break;
case 3:
C=tecla;
break;
case 4:
D=tecla;
break;
default:
digito=5;
break;
}
if (digito>4)
;
else
printf("%d",tecla);
break;
}
}...
tracking img