?? jianfei.c
字號:
//ICC-AVR application builder : 2005-7-23 23:28:34
// Target : M8
// Crystal: 8.0000Mhz
#include "iom8v.h"
#include "macros.h"
#define sbipc0 asm("SBI 0X15,0")
#define cbipc0 asm("CBI 0X15,0")
#define sbipc1 asm("SBI 0X15,1")
#define cbipc1 asm("CBI 0X15,1")
#define sbipc2 asm("SBI 0X15,2")
#define cbipc2 asm("CBI 0X15,2")
#define sbipc3 asm("SBI 0X15,3")
#define cbipc3 asm("CBI 0X15,3")
#define sbipc4 asm("SBI 0X15,4")
#define cbipc4 asm("CBI 0X15,4")
#define sbipb0 asm("SBI 0X18,0")
#define cbipb0 asm("CBI 0X18,0")
#define sbipb1 asm("SBI 0X18,1")
#define cbipb1 asm("CBI 0X18,1")
#define sbipb2 asm("SBI 0X18,2")
#define cbipb2 asm("CBI 0X18,2")
#define sbipb3 asm("SBI 0X18,3")
#define cbipb3 asm("CBI 0X18,3")
#define sbipb4 asm("SBI 0X18,4")
#define cbipb4 asm("CBI 0X18,4")
#define sbipb5 asm("SBI 0X18,5")
#define cbipb5 asm("CBI 0X18,5")
#define sbipb6 asm("SBI 0X18,6")
#define cbipb6 asm("CBI 0X18,6")
#define sbipb7 asm("SBI 0X18,7")
#define cbipb7 asm("CBI 0X18,7")
#define sbipd0 asm("SBI 0x12,0")
#define cbipd0 asm("CBI 0x12,0")
#define sbipd3 asm("SBI 0x12,3")
#define cbipd3 asm("CBI 0x12,3")
#define sbipd4 asm("SBI 0x12,4")
#define cbipd4 asm("CBI 0x12,4")
#define sbipd5 asm("SBI 0x12,5")
#define cbipd5 asm("CBI 0x12,5")
#define sbipd6 asm("SBI 0x12,6")
#define cbipd6 asm("CBI 0x12,6")
#define sbipd7 asm("SBI 0x12,7")
#define cbipd7 asm("CBI 0x12,7")
#define la 0x01
#define lb 0x02
#define lc 0x04
#define ld 0x08
#define le 0x10
#define lf 0x20
#define lg 0x40
#define ldp 0x80
#define uchar unsigned char
unsigned char tran1=1,xunhuan1=1;
unsigned int trign=0;
unsigned char temppower=0,powerfang=1;
unsigned char modus=0,tempset=0,energy=0;
unsigned char hao=0, second=0,minute=30;
unsigned char outv[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char selmodle=1;
unsigned char fecte=0,boxing1=0,boxing2=0;
unsigned char timer2=0,ponoff=0;
unsigned char ram[8];
unsigned char modsec=0,share=1;
unsigned char tempture1=0,tempture2=0,temptrig=0;
void settemp(void);
/* 微秒級延時程序 */
void delay_us(int time)
{
do
{
time--;
WDR();
}
while (time>1);
}
/* 毫秒級延時程序 */
void delay_ms(unsigned int time)
{
while(time!=0)
{
delay_us(500);
time--;
}
}
void beep(void)
{ sbipb0;
delay_ms(200);
cbipb0;
}
void initram(void)
{unsigned char i;
for (i=0;i<8;i++) ram[i]=0;
}
void contoram(void)
{
unsigned char temp=0;
initram();
temp=outv[(minute/10)];
if ((temp & la)!=0) ram[0]|=0x40;
if ((temp & lf)!=0) ram[0]|=0x01;
if ((temp & lg)!=0) ram[0]|=0x02;
if ((temp & le)!=0) ram[0]|=0x04;
if ((temp & ld)!=0) ram[0]|=0x08;
if ((temp & lc)!=0) ram[0]|=0x10;
if ((temp & lb)!=0) ram[0]|=0x20;
temp=outv[(minute%10)];
if ((temp & lf)!=0) ram[0]|=0x80;
if ((temp & lg)!=0) ram[1]|=0x01;
if ((temp & le)!=0) ram[1]|=0x02;
if ((temp & ld)!=0) ram[1]|=0x04;
if ((temp & lc)!=0) ram[1]|=0x08;
if ((temp & lb)!=0) ram[1]|=0x10;
if ((temp & la)!=0) ram[1]|=0x20;
switch (tempset)
{case 0:
ram[1]|=0x40;
break;
case 1:
ram[1]|=0x80;
break;
case 2:
ram[2]|=0x01;
break;
case 3:
ram[2]|=0x20;
break;
case 4:
ram[2]|=0x40;
break;
case 5:
ram[2]|=0x80;
break;
}
switch (modus)
{case 0: //HANDWORK
ram[2]|=0x02;
break;
case 1: //AUTO1
ram[2]|=0x04;
break;
case 2: //AUTO2
ram[2]|=0x08;
break;
}
ram[2]|=0x10;
temp=outv[(energy/10)];
if ((temp & lf)!=0) ram[4]|=0x10;
if ((temp & lg)!=0) ram[4]|=0x20;
if ((temp & le)!=0) ram[4]|=0x40;
if ((temp & ld)!=0) ram[4]|=0x80;
if ((temp & lc)!=0) ram[5]|=0x01;
if ((temp & lb)!=0) ram[5]|=0x02;
if ((temp & la)!=0) ram[5]|=0x04;
temp=outv[(energy%10)];
if ((temp & lf)!=0) ram[5]|=0x08;
if ((temp & lg)!=0) ram[5]|=0x10;
if ((temp & le)!=0) ram[5]|=0x20;
if ((temp & ld)!=0) ram[5]|=0x40;
if ((temp & lc)!=0) ram[5]|=0x80;
if ((temp & lb)!=0) ram[6]|=0x01;
if ((temp & la)!=0) ram[6]|=0x02;
switch (selmodle)
{case 1:
ram[6]|=0x08 * share;
break;
case 2:
ram[6]|=0x10* share;
break;
case 3:
ram[6]|=0x80* share;
break;
case 4:
ram[6]|=0x04* share;
break;
case 5:
ram[6]|=0x20* share;
break;
case 6:
ram[7]|=0x01* share;
break;
}
ram[6]|=0x40;
}
void port_init(void)
{
PORTB = 0x00;
DDRB = 0xff;
PORTC = 0x38;
DDRC = 0xff;
PORTD = 0x8f;
DDRD = 0xf0;
}
void sendadd(unsigned char temp)
{unsigned char i;
for (i=0;i<8;i++)
{
if ((temp & (0x80>>i))!=0) sbipb4; else cbipb4;
NOP();
sbipb3;
NOP();
cbipb3; ///clk
NOP();
}
}
void disablevfd(void)
{
PORTB |=0X60;
}
void enablevfd(void)
{
PORTB &=0X9F;
}
void show(void)
{
unsigned char i;
contoram();
disablevfd();
for (i=8;i>0;i--) sendadd(ram[i-1]);
enablevfd();
}
void powerdown(void)
{
OCR1A=0;
OCR1B=0;
}
void set_power(void)
{
//OCR1A=ICR1/250*energy;
//OCR1B=OCR1A;
OCR1A=energy;
OCR1B=energy;
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 30Hz
// actual value: 30.048Hz (0.2%)
void in30hza(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x02;
ICR1L = 0x08;
set_power();
TCCR1A = 0x82;
TCCR1B = 0x14; //start Timer
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 30Hz
// actual value: 30.048Hz (0.2%)
void in30hzb(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x02;
ICR1L = 0x08;
set_power();
TCCR1A = 0x22;
TCCR1B = 0x14; //start Timer
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 50Hz
// actual value: 50.080Hz (0.2%)
void in50hza(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x01;
ICR1L = 0x38;
set_power();
TCCR1A = 0x82;
TCCR1B = 0x14; //start Timer
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 50Hz
// actual value: 50.080Hz (0.2%)
void in50hzb(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x01;
ICR1L = 0x38;
set_power();
TCCR1A = 0x22;
TCCR1B = 0x14; //start Timer
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 90Hz
// actual value: 90.318Hz (0.4%)
void in90hza(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x00;
ICR1L = 0xAD;
set_power();
TCCR1A = 0x82;
TCCR1B = 0x14; //start Timer
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 90Hz
// actual value: 90.318Hz (0.4%)
void in90hzb(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x00;
ICR1L = 0xAD;
set_power();
TCCR1A = 0x22;
TCCR1B = 0x14; //start Timer
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 10Hz
// actual value: 10.003Hz (0.0%)
void in10hza(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x06;
ICR1L = 0x1A;
set_power();
TCCR1A = 0x82;
TCCR1B = 0x14; //start Timer
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 10Hz
// actual value: 10.003Hz (0.0%)
void in10hzb(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x06;
ICR1L = 0x1A;
set_power();
TCCR1A = 0x22;
TCCR1B = 0x14; //start Timer
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 5Hz
// actual value: 5.000Hz (0.0%)
void in5hza(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x0C;
ICR1L = 0x35;
set_power();
TCCR1A = 0x82;
TCCR1B = 0x14; //start Timer
}
//TIMER1 initialize - prescale:256
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 5Hz
// actual value: 5.000Hz (0.0%)
void in5hzb(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0; //setup
TCNT1L = 0;
ICR1H = 0x0C;
ICR1L = 0x35;
set_power();
TCCR1A = 0x22;
TCCR1B = 0x14; //start Timer
}
void stopboxing(void)
{
TCCR1A=0x00;
TCCR1B = 0x00; //stop
cbipb1;
cbipb2;
}
void modle1(void) //捶擊
{
boxing1=60;
boxing2=140;
in50hza();
}
void modle2(void) //變頻
{
in5hza();
}
void modle3(void) //鋸齒波
{
in50hza();
}
void modle4(void) //頻率變化
{
in30hza();
}
void modle5(void) //
{
in50hza();
}
void modle6(void) //間隙波
{
in30hza();
}
void chmodle(void)
{
tran1=1;
xunhuan1=1;
fecte=0;
trign=0;
switch (selmodle)
{case 1:
modle1();
break;
case 2:
modle2();
break;
case 3:
modle3();
break;
case 4:
modle4();
break;
case 5:
modle5();
break;
case 6:
modle6();
break;
}
}
void stop(void)
{
TCCR2 = 0x00; //溫度調整,強度調節
TIFR |=0XFF;
sbipc3;
sbipd7;
TCCR0 = 0x00; //stop
TIFR |=0X01;
share=1;
stopboxing();
ponoff=0;
}
void begin(void)
{
if (minute>0)
{
chmodle();
TCCR0 = 0x04; //start timer
settemp();
TCCR2 = 0x07; //start
ponoff=1;
}
}
//調溫輸入為220AC,16AC
void settemp(void)
{
switch (tempset)
{case 0:
tempture1=0;
tempture2=0;
break;
case 1:
tempture1=50;
tempture2=50;
break;
case 2:
tempture1=65;
tempture2=65;
break;
case 3:
tempture1=80;
tempture2=80;
break;
case 4:
tempture1=90;
tempture2=90;
break;
case 5:
tempture1=100;
tempture2=100;
break;
}
}
void checkbut(void)
{
unsigned char temp;
unsigned char i;
PORTD|=0x7f;
NOP();
cbipd4;
NOP();
temp=(PIND & 0x0f);
if (temp!=0x0f)
{ beep();
switch (temp)
{
case 0x0e: //selmodle--
if (modus==0 && selmodle>1) selmodle--;
if (ponoff==1) chmodle();
break;
case 0x0d: //selmodle++
if (modus==0 && selmodle<6) selmodle++;
if (ponoff==1) chmodle();
break;
case 0x0b: //energy--
if ( energy>0) energy--;
if (ponoff==1) set_power();
break;
}
show();
while ((PIND & 0x0f)!=0x0f) WDR();
delay_ms(100);
while ((PIND & 0x0f)!=0x0f) WDR();
}
PORTD|=0x7f;
NOP();
cbipd5;
NOP();
temp=(PIND & 0x0f);
if (temp!=0x0f)
{beep();
switch (temp)
{case 0x0e: //energy++
if (energy<10) energy++;
if (ponoff==1) set_power();
break;
case 0x0d: //on/off
if (ponoff==0 && minute>0) begin(); else stop();
break;
case 0x0b: //modus++
if (modus<2) modus++; else modus=0;
break;
}
show();
while ((PIND & 0x0f)!=0x0f) WDR();
delay_ms(100);
while ((PIND & 0x0f)!=0x0f) WDR();
}
PORTD|=0x7f;
NOP();
cbipd6;
NOP();
temp=(PIND & 0x0f);
if (temp!=0x0f)
{beep();
switch (temp)
{case 0x0e: //tempset++
if (tempset<5) tempset++; else tempset=0;
if (ponoff==1) settemp();
break;
case 0x0d: //time--
if (minute>1) minute--;
for (i=0;i<40;i++)
{delay_ms(20);
show();
if ((PIND & 0x0f)!= temp) break;}
while((PIND & 0x0f)==temp)
{
beep();
if (minute>1) minute--;
delay_ms(120);
show();}
break;
case 0x0b: //time++
if (minute<99) minute++;
for (i=0;i<40;i++)
{delay_ms(20);
show();
if ((PIND & 0X0f)!= temp) break;}
while((PIND & 0x0f)==temp)
{ if (minute<99) minute++;
beep();
show();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -