#include <iom16v.h>
#include <macros.h>
const unsigned char word1[12]={0xb3,0xa4,0xb4,
0xba,0xc0,0xed,0xb9,0xa4,0xb4,0xf3,0xd1,0xa7};
//长春理工大学
const unsigned char word2[12]={0xb5,0xe7,0xd0,
0xc5,0xb9,0xa4,0xb3,0xcc,0xd1,0xa7,0xd4,0xba};
//电信工程学院
const unsigned char word3[14]={0xb9,0xe2,0xb5,
0xe7,0xbc,0xec,0xb2,0xe2,0xca,0xb5,0xd1,
0xe9,0xcf,0xe4}; //光电检测实验箱
const unsigned char word4[6]={0xc7,0xeb,0xb0,
0xb4,0xbc,0xfc};//请按键
unsigned char key;
void delay_1ms(void)
{
unsigned char i;
for(i=1142;i>0;i--);
}
void delay_nms(unsigned char n)
{
for(;n>0;n--)
{
delay_1ms();
}
}
void port_init(void)
{
DDRA=0x00;
PORTA=0xFF;
DDRC=0x00;
DDRB=0xFF;
}
unsigned char key_check(void)
{
unsigned char temp,pemp1;
PORTC&=0xFC;
temp=PINC;
if(temp!=0xFF)
{
delay_nms(10);
temp1=PINC;
if(temp1==temp)
{
return 1;
}
else
return 0;
}
return 0;
}
void key_out(void)
{
unsigned char i;
while(1)
{
i=PINA;
if(i=0xFF)
{
delay_nms(10);
t=PINA;
if(i==0xFF)
{
break;
}
}
}
}
void key_value(void)
{
unsigned char i;
unsigned char temp;
for(i=2;i>0;i--)
{
PORTC~=(1<<i);
delay_1ms();
temp=PINA;
switch(temp)
{
case 0b11111110:key1=(i<<3)+1;break;
case 0b11111101:key1=(i<<3)+2;break;
case 0b11111011:key1=(i<<3)+3;break;
case 0b11110111:key1=(i<<3)+4;break;
case 0b11101111:key1=(i<<3)+5;break;
case 0b11011111:key1=(i<<3)+6;break;
case 0b10111111:key1=(i<<3)+7;break;
case 0b01111111:key1=(i<<3)+8;break;
default:break;
}
key_out();
}
}
void spi_init()
{
DDRB=(1<<MOSI)|(1<<SS)|(1<<SCK);
SPCR=(1<<SPE)|(1<<MSTR)|(1<<CPOL)|(1<<CPHA)|(1<<SPR0)|(1<<SPR1);
SPSR=0x00;
}
void spi_sd(unsigned char data)
{
SPDR=data;
while(!(SPSR=(1<<SPIF)));
}
void lcd_write(unsigned char d,unsigned char s)
{
if(s)
{
PORTC|=(1<<SS);
spi_sd(0xf8);
spi_sd(d&0xf0);
spi_sd(d<<4);
PORTC&=~(1<<SS);
if(d=0x01)
{
dalay_nms(6);
}
else
delay_nms(1);
}
else
{
PORTC|=(1<<SS);
spi_sd(0xf8);
spi_sd(d&0xf0);
spi_sd(d<<4);
PORTC&=~(1<<SS);
delay_nms(10);
}
}
void lcd_init(void)
{
delay_nms(20);
lcd_write(0x30,1);
lcd_write(0x0c,1);
lcd_write(0x01,1);
}
void lcd_display(void)
{
unsigned char k;
lcd_write(0x01,1);
delay_nms(21);
lcd_write(0x81,1);
delay_nms(20);
for(k=0;k<12;k++)
{
lcd_write(word1[k],1);
}
delay_nms(10);
lcd_write(0x91,1);
delay_nms(10);
for(k=0;k<14;i++)
{
lcd_write(word2[k],1);
}
delay_nms(10);
lcd_write(0x89,1);
delay_nms(10);
for(k=0;k<14;k++)
{
lcd_write(word3[k],0);
}
delay_nms(10);
lcd_write(0x01,1);
lcd_write(0x92,1);
delay_nms(10);
for(k=0;k<6;k++)
{
lcd_write(word4[k],0);
}
delay_nms(10000);
}
void key_process(void)
{
unsigned char k;
switch(key)
{
case 1:lcd_write(0x31,0);break;
case 2:lcd_write(0x01,1); //清屏
delay_nms(10);
lcd_write(0x81,1); //确定显示的位置
delay_nms(10);
for(k=0;k<12;k++)
{
lcd_write(word1[k],0);};break;
case 3:lcd_write(0x33,0);break;
case 4:lcd_write(0x34,0);break;
case 5:lcd_write(0x35,0);break;
case 6:lcd_write(0x36,0);break;
case 7:lcd_write(0x37,0);break;
case 8:lcd_write(0x38,0);break;
case 9:lcd_write(0x39,0);break;
case 10:lcd_write(0x41,0);break;
case 11:lcd_write(0x42,0);break;
case 12:lcd_write(0x43,0);break;
case 13:lcd_write(0x44,0);break;
case 14:lcd_write(0x45,0);break;
case 15:lcd_write(0x46,0);break;
case16:lcd_init();lcd_display(); delay_nms(10000);lcd_write(0x01,1);break;
}
}
评论0