麻烦哪位大神帮我改一下,谢谢
#include<iom16v.h>#include<macros.h> #define uchar unsigned char#define uint unsigned char #include"LM016LCD_drive.h"#include"MAX6675_drive.h"#include"DS1302_drive.h"#include"PWM.h" #define beep_0 (PORTD=PORTD&0X7F)#define beep_1 (PORTD=PORTD|0X81)#define fosc 11059200#define baud 9600 uchar count_10ms;uchar K1_FLAG=1;uchar tempt;uchar SEED;uchar K1=0;uchar P=0;//uchar K=0;uchar line1_data[]={"week"};//uchar line3_data[]={"
time"};//uchar line2_data[]={" "};uchar disp_buf[15]={0x00};uchar time_buf[7]={0,0,0x12,0,0,0,0,};uchar temp[2]={0}; //uchar TEMP1[]={0};/*
蜂鸣器响一声函数*/void beep(uchar L){beep_0;Delay_ms(L);beep_1;Delay_ms(L);} /*
端口设置函数*/void port_init(void){PORTA=0xff;DDRA=0XFF;DDRB=(1<<PB0)|(1<<PB2)|(1<<PB3)|(1<<PB4)|(1<<PB6)|(1<<PB7); PORTC=0XFF;DDRC=0XFF;DDRD=(0<<PD2)|(0<<PD3)|(0<<PD4)|(0<<PD5)|(0<<PD6)|(1<<PD7);PORTD=0Xff;} /*
转换函数,负责将走时数据转换为适合lcd显示的数据*/void LCD_conv(uchar inl,uchar in2,uchar in3,uchar in4,uchar in5,uchar in6,uchar in7){disp_buf[0]=inl/10+0x30;disp_buf[1]=inl%10+0x30;disp_buf[2]=in2/10+0x30;disp_buf[3]=in2%10+0x30;disp_buf[4]=in3/10+0x30;disp_buf[5]=in3%10+0x30;disp_buf[6]=in4/10+0x30;disp_buf[7]=in4%10+0x30;disp_buf[8]=in5/10+0x30;disp_buf[9]=in5%10+0x30;disp_buf[10]=in6+0x30;//disp_buf[11]=2+0x30;disp_buf[12]=0x30;disp_buf[13]=in7%100/10+0x30;disp_buf[14]=in7%10+0x30;} void temp_disp(void){uint i;LocateXY(11,1);for(i=1;i<4;i++){lcd_wdat(show_data
);delay(1);}LocateXY(14,1);lcd_wdat(0xdf);lcd_wdat(0x43);} /*lcd显示函数*/void LCD_disp(){uchar i; //LocateXY(10,0);//lcd_wdat(0x3a);LocateXY(0,0);lcd_wdat(disp_buf[11]);lcd_wdat(disp_buf[12]);lcd_wdat(disp_buf[13]);lcd_wdat(disp_buf[14]);lcd_wdat(0x2f);lcd_wdat(disp_buf[8]);lcd_wdat(disp_buf[9]);lcd_wdat(0x2f);lcd_wdat(disp_buf[6]);lcd_wdat(disp_buf[7]); LocateXY(15,0);lcd_wdat(disp_buf[10]); LocateXY(0,1);lcd_wdat(disp_buf[4]);lcd_wdat(disp_buf[5]);lcd_wdat(0x3a);lcd_wdat(disp_buf[2]);lcd_wdat(disp_buf[3]);lcd_wdat(0x3a);lcd_wdat(disp_buf[0]);lcd_wdat(disp_buf[1]); } /*定时器1初始化*//*void timer1_init(){SREG=0X80;//MCUCR=(1<<ISC01)|(1<<ISC00); TIMSK|=(1<<TOIE1);TCNT1H=0XFb;TCNT1L=0X1e;TCCR1A|=0X00;TCCR1B|=(1<<CS11)|(1<<CS10);}*//*#pragma interrupt_handler timer0_ovf:10void timer0_ovf(void){ }*//*定时器1终端服务函数*//*#pragma interrupt_handler timer1_ovf:9void timer1_ovf(void){ }*/ //}/*if(count_10ms>=100){count_10ms=0;time_buf[0]++;if(time_buf[0]==60){time_buf[0]=0;time_buf[1]++;if(time_buf[1]==60){time_buf[1]=0;time_buf[2]++;if(time_buf[2]==24){time_buf[0]=0;time_buf[1]=0;time_buf[2]=0;}}}}}*//*按键处理函数*/void KeyProcess(){uint i;uchar K;uchar L;uchar sec16,min16,hour16,day16,mon16,year16,week16;write_ds1302(0x8e,0x00);write_ds1302(0x80,0x80); Delay_ms(10); if((PIND&0X08)==0){while(!(PIND&0X08));beep(100);K=K1_FLAG;switch(K){/*case 1:{time_buf[0]=time_buf[0]+1;if(time_buf[0]==60)time_buf[0]=0;sec16=time_buf[0]/10*16+time_buf[0]%10;write_ds1302(0x80,sec16);}*///break;case 1:{time_buf[1]=time_buf[1]+1;if(time_buf[1]==60)time_buf[1]=0;min16=time_buf[1]/10*16+time_buf[1]%10;write_ds1302(0x82,min16);}break;case 2:{time_buf[2]=time_buf[2]+1;if(time_buf[2]==24)time_buf[2]=0;hour16=time_buf[2]/10*16+time_buf[2]%10;write_ds1302(0x84,hour16);}break;case 3:{time_buf[5]=time_buf[5]+1;if(time_buf[5]==8)time_buf[5]=1;week16=time_buf[5]/10*16+time_buf[5]%10;write_ds1302(0x8a,week16);}break;case 4:{time_buf[3]=time_buf[3]+1;if(time_buf[3]==31)time_buf[3]=1;day16=time_buf[3]/10*16+time_buf[3]%10;write_ds1302(0x86,day16);}break;case 5:{time_buf[4]=time_buf[4]+1;if(time_buf[4]==12)time_buf[4]=0;mon16=time_buf[4]/10*16+time_buf[4]%10;write_ds1302(0x88,mon16);}break;case 6:{time_buf[6]=time_buf[6]+1;if(time_buf[6]==99)time_buf[6]=0;year16=time_buf[6]/10*16+time_buf[6]%10;write_ds1302(0x8c,year16);}break;default:break;}} if((PIND&0X10)==0){ while(!(PIND&0X10));beep(100);L=K1_FLAG;switch(L){ /*case 1:{time_buf[0]=time_buf[0]-1;if(time_buf[0]==0)time_buf[0]=59;sec16=time_buf[0]/10*16+time_buf[0]%10;write_ds1302(0x80,sec16);}*///break;case 1:{time_buf[1]=time_buf[1]-1;if(time_buf[1]==0)time_buf[1]=59;min16=time_buf[1]/10*16+time_buf[1]%10;//Delay_ms(150);write_ds1302(0x82,min16);}break; case 2:{time_buf[2]=time_buf[2]-1;if(time_buf[2]==0)time_buf[2]=23;hour16=time_buf[2]/10*16+time_buf[2]%10;//Delay_ms(150);write_ds1302(0x84,hour16);}break;case 3:{time_buf[5]=time_buf[5]-1;if(time_buf[5]==0)time_buf[5]=7;week16=time_buf[5]/10*16+time_buf[5]%10;write_ds1302(0x8a,week16);}break;case 4:{time_buf[3]=time_buf[3]-1;if(time_buf[3]==0)time_buf[3]=31;day16=time_buf[3]/10*16+time_buf[3]%10;//Delay_ms(150);write_ds1302(0x86,day16);}break; case 5:{time_buf[4]=time_buf[4]-1;if(time_buf[4]==0)time_buf[4]=12;mon16=time_buf[4]/10*16+time_buf[4]%10;//Delay_ms(150);write_ds1302(0x88,mon16);}break; case 6:{time_buf[6]=time_buf[6]-1;if(time_buf[6]==0)time_buf[6]=99;year16=time_buf[6]/10*16+time_buf[6]%10;//Delay_ms(150);write_ds1302(0x8c,year16);}break; default:break;}} }/*if((PIND&0X08)==0){ while(!(PIND&0X08));beep();time_buf[2]=time_buf[2]+1;if(time_buf[2]==24)time_buf[2]=0;hour16=time_buf[2]/10*16+time_buf[2]%10;write_ds1302(0x84,hour16);}if((PIND&0X10)==0){while(!(PIND&0X10));beep();time_buf[1]=time_buf[1]+1;if(time_buf[1]==60)time_buf[1]=0;min16=time_buf[1]/10*16+time_buf[1]%10;write_ds1302(0x82,min16);}*/ /*读取时间函数,并转化为十进制*/void get_data(){uchar sec,min,hour,day,mon,week,year;write_ds1302(0x8e,0x00);write_ds1302(0x90,0xab);sec=read_ds1302(0x81);min=read_ds1302(0x83);hour=read_ds1302(0x85);day=read_ds1302(0x87);mon=read_ds1302(0x89);week=read_ds1302(0x8b);year=read_ds1302(0x8d);time_buf[0]=sec/16*10+sec%16;time_buf[1]=min/16*10+min%16;time_buf[2]=hour/16*10+hour%16;time_buf[3]=day/16*10+day%16;time_buf[4]=mon/16*10+mon%16;time_buf[5]=week/16*10+week%16;time_buf[6]=year/16*10+year%16;}/************温度-PWM转换函数******/void Temp_PWM(){uint i;if(TEMP<=0){tempt=-1;}if(TEMP>0&&TEMP<300){tempt=-1;}if(TEMP>=300&&TEMP<500){tempt=256*(500-TEMP)/500;}if(TEMP>=500){tempt=1;beep(i);}} /*******串口初始化********/void uart0_Init(void){ UCSRB=0x00; UCSRA=0X00;//发射器使能 /*设置帧格式*/ UCSRC|= (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);//工作模式 ,8位字符,1位停止位 // UCSRC=0x86; /*设置波特率*/ UBRRL=(fosc/16/(baud+1))%256; UBRRH=(fosc/16/(baud+1))/256; /*接收器与发送器使能*/ UCSRB|=(1<<RXCIE)|(1<<RXEN)|(1<<TXEN);//UCSRB=0x98; SREG|=BIT(7);}/*******发送数据函数********/void UART0_send(uchar i){uchar j;while(!(UCSRA&(1<<UDRE)));for(j=0;j<3;j++){UDR=i;}} void Usart_PutString(unsigned char *s){while(*s){UART0_send(*s++);}UART0_send(0x0d);UART0_send(0x0a);}/*主函数*/void main(void){uint i;uint JISHU;port_init();init_ds1302();lcd_init();lcd_clr();//SREG=0X80;uart0_Init();//INT0_init();//max6675_init();//PWM_Init_IO();TIMER0_Init();//timer1_init();LCD_write_str(11,0,line1_data);while(1){if((PIND&0X40)==0){Delay_ms(10);if((PIND&0X04)==0){while(!(PIND&0X04));beep(100);K1_FLAG++;if(K1_FLAG>6)K1_FLAG=1;}KeyProcess();} if((PIND&0X40)==0X40){MAX6675_conv();temp_disp();} if((PIND&0X20)==0){while(!(PIND&0X20));beep(100);write_ds1302(0x80,0x00);write_ds1302(0x8e,0x80);K1_FLAG=0;Delay_ms(15);}get_data();LCD_conv(time_buf[0],time_buf[1],time_buf[2],time_buf[3],time_buf[4],time_buf[5],time_buf[6]);LCD_disp();Temp_PWM();PWM_control(tempt);//SEED=TEMP/10%16+TEMP%10;for(i=1;i<4;i++){UART0_send(show_data);}UART0_send(0x0d);UART0_send(0x0a);//Usart_PutString("温度");} } /*********发送结束中断函数*******//*#pragma interrupt_handler UART0_TXD_vect:12void UART0_TXD_vect(void){SEED=TEMP;UART0_send(SEED);Usart_PutString("温度");}*/麻烦哪位大神帮我改一下,谢谢谢谢谢
一周热门 更多>