基于STC89c52RC单片机的智能风扇设计

光电信息协会电子设计竞赛 钟培文小组

lcdrs=0; lcden=1; P0=com; lcden=0; }

void write_data(uchar Data) {

Delayms(5); lcdrs=1; lcden=1; P0=Data; ; lcden=0; }

void write_string(uchar x,uchar y,uchar *s) { if (y == 0) {

write_com(0x80 + x); } else {

write_com(0xC0 + x); } while (*s) {

write_data( *s); s ++; }

//写入1602字符串

29

光电信息协会电子设计竞赛 钟培文小组

}

void write_char(uchar x,uchar y,uchar Data) { if (y == 0) {

write_com(0x80 + x); } else {

write_com(0xC0 + x); }

write_data(Data); }

void Init_1602(void) {

lcden=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); }

void display2(void) {

write_string(4,0,table_1); write_string(0,1,table_21); write_string(6,1,table_22); }

void change_display2(void)

//初始化1602参数

//1602写字符

30

光电信息协会电子设计竞赛 钟培文小组

{

uchar time_asc[5],a;

time_asc[0]=time2/10000+0x30; time_asc[1]=time2000/1000+0x30; time_asc[2]=time200000/100+0x30; time_asc[3]=time2000000/10+0x30; time_asc[4]=time2000000+0x30; if(timing_on==1) {

for(a=0;a<5;a++)

write_char(11+a,1,time_asc[a]); }

if(timing_flag==0 && timing_on==0) {

write_string(14,1,\ \write_string(11,1,\}

if(run_flag) {

write_string(2,0,\} else

write_string(4,0,table_1); switch(i) {

case 1: write_char(2,1,'1');break; case 2: write_char(2,1,'2');break; case 3: write_char(2,1,'3');break; default: write_char(2,1,'0'); } switch(j) {

case 1: write_char(8,1,'1');break;

31

光电信息协会电子设计竞赛 钟培文小组

case 2: write_char(8,1,'2');break; case 3: write_char(8,1,'3');break; default: write_char(8,1,'0'); } }

//红外部分 /*------------------------------------------------ 外部中断0中断处理 ------------------------------------------------*/

void Ex0_ir (void) interrupt 0 //外部中断0服务函数 {

static unsigned char i; //接收红外信号处理 static bit startflag; //是否开始处理标志位

if(startflag) {

if((irtime/10)<63&&(irtime>=33))//引导码 TC9012的头码,9ms+4.5ms

i=0;

irdata[i]=irtime;//存储每个电平的持续时间,用于以后判断是0还是1 irtime=0; i++; if(i==33) { irok=1; i=0; }

} else { irtime=0; startflag=1;

32

联系客服:779662525#qq.com(#替换为@)