/*
* GccApplication1.c
*
* Created: 2016/6/17 19:31:04
* Author: lenovo
*/
#include <avr/io.h>
#include <util/delay.h>
#include"12864.h"
#include <avr/interrupt.h>
#define data1 PORTD|=(1<<6)
#define data0 PORTD&=~(1<<6)
#define data_d PIND&(1<<6)
#define SCLK PIND&(1<<2)
#define uchar unsigned char
#define uint unsigned int
uint num=0,zhi;
uchar keyv=0,BF=0,key_up=0;
void keyscan()//把读到的数据转化成整型,用12864显示
{
zhi=(uint)(keyv);
send_cmd(0x90);
send_data(0x30+zhi/100);
send_data(0x30+zhi%100/10);
send_data(0x30+zhi%10);
BF=0;
}
int main(void)
{
DDRD&=~(1<<2);
DDRB|=(1<<0)|(1<<1);
DDRD&=~(1<<6);
MCUCR|=(1<<ISC00);
GICR|=(1<<INT0);
sei();
init_12864();
//send_cmd(0x80);
//send_data(0x32);
while(1)
{
if(BF)
keyscan();
else
sei();
}
}
SIGNAL(SIG_INTERRUPT0)
{
if(num>0&&num<9)
{
keyv=keyv>>1;
if(data_d)
{
keyv|=0x80;
}
}
num++;
while(!SCLK);
if(num>10)
{
num=0;
BF=1;
cli();
}
} |