#include"mega128.h" #include"yejing.c" #include"jianpan.c" #include"delay.h" #include"chuankou.c" #include"biao.c" #pragma regalloc- register unsigned int temp_a@6; //固定分配寄存器 register unsigned int temp_b@8; register unsigned int temp_c@10; #pragma regalloc+ unsigned char shu=0; unsigned char temp_tcnt3_h=0xf9; unsigned char temp_tcnt3_l=0x29; void jisuan(float w) {float temp; unsigned char temp1=0; unsigned char temp2=0; unsigned int bao=0; if(w>=20&&w<45)w=w*1.0025; else if(w>=45&&w<65)w=w*1.0055; else if(w>=65&&w<70)w=w*1.0065; else if(w>=70&&w<80)w=w*1.0075; else if(w>=80&&w<90)w=w*1.0083; else if(w>=90)w=w*1.0095; temp=1000000.0/(float)w/60.0/0.0625; temp=65536.0-temp; bao=temp; xianshi(temp,0); temp1=bao%256; temp2=bao/256; while(!(ETIFR&0x04));//等待定时器3的中断 temp_tcnt3_l=temp1; temp_tcnt3_h=temp2; } main() {unsigned char i=0; unsigned char re_data; float pinlv=0.0; unsigned long k=0; delay_ms(200); TCCR0=0x19;//工作在CTC模式,为8279提供工作频率 OCR0=0x02; DDRD.0=0; PORTD.0=1; MCUCR|=0xc0;//外部存储器使能 XMCRA|=0x0e;//在写入外部存储器的时候就可以等待两个时钟周期 lcd_reset(); init_8279(); PORTD.1=1; DDRD.1=0; for(i=0;i<11;i++)lcd_chinese(0,4+2*i,i); lcd_chinese(3,0,15); lcd_chinese(3,2,16); lcd_word(4,4,26); DDRB=0xff; TCCR1A=0xff;//三个比较器在比较匹配的时候置位//工作在10位快速PWM TCCR1B=0x09; TIMSK|=0x04;//定时器1的溢出中断使能 OCR1A=0xff; TCCR3A=0x00;//定时器3工作在普通定时模式 TCCR3B=1;//定时器3不需要分频 ETIMSK|=0x04;//定时器3溢出中断使能 #asm("sei") jisuan(50.0); while(1) { if(PIND.1) {send_8279_com(0x40); //读键盘的0地址里面的键值 key=read_8279_data(); for(k=0;k<19;k++)if(key==keybord[k])break; if(k==18){jisuan(pinlv);pinlv=0;k=0;} pinlv=pinlv*10; pinlv+=k; xianshi8279(pinlv,0); } } } #pragma savereg- //屏蔽在中端中压栈 interrupt [15] void int11() {#asm push r30 out 0x2B,R7 //OCR1A=temp_a; out 0x2A,R6 out 0x29,R9 //OCR1B=temp_b; out 0x28,R8 STS 121,R11 //OCR1C=temp_c; STS 120,R10 #endasm TIMSK&=0xFB; #asm pop r30 #endasm } #pragma savereg+ interrupt [30] void int33() {TCNT3H=temp_tcnt3_h; TCNT3L=temp_tcnt3_l; shu++; if(shu==60)shu=0; temp_a=512+spwm_biao_60_a[shu]; temp_b=512+spwm_biao_60_b[shu]; temp_c=512+spwm_biao_60_c[shu]; TIMSK|=0x04; }