单片机源程序如下:
#include "Main.h"
SIGNAL(SIG_OVERFLOW0) //中断每1秒发一个数
{
TCNT0 = 200;
TIMSK &= ~_BV(TOIE0); //TIMSK中TOIE0置0
if(++g_bCount>1)
{
g_bCount = 0;
TaskInTimer();
}
/*if(++g_aCount > 44) //3s定时
{
g_aCount = 0;
Table_Locked();
}*/
TIMSK |= _BV(TOIE0); //开中断
}
SIGNAL(SIG_OVERFLOW2) //中断每1秒发一个数
{
TCNT2 = 150;
TIMSK &= ~_BV(TOIE2); //TIMSK中TOIE2置0 关闭中断
if(++Time_Count > 21) //3s定时
{
Time_Count = 0;
//flag_3s = 1;
Table_Locked();
}
TIMSK |= _BV(TOIE2); //开中断
}
void Init()
{
cli(); //关闭所有中断
Key_Init();
PortInit();
Time_Init();
sei(); //打开所有中断
InitADC();
}
void Delay_1ms()
{
uint i;
for(i = 0;i < 570;i--)
;
}
void Delay_1s()
{
uint i;
for(i = 0;i < 2000;i++)
{
Delay_1ms();
}
}
void Delay_xs(uint x)
{
uint i;
for(i = 0;i < x;i++)
{
Delay_1s();
}
}
void PortInit()
{
DDRA = 0xff;
PORTA = 0xe2; //LED 0xe2
DDRC = 0xff;
PORTC = 0xff; //Motor
DDRE = 0x00;
PORTE = 0xf8; //Remote Control
DDRF =0x00; //ADC
PORTF = 0x00;
}
void Time_Init()
{
TCNT0 = 200;
g_bCount = 0;
TCCR0 = _BV(CS02)|_BV(CS00)|_BV(CS01); //CS02置1,CS00,cs01置1 //1024分频
TIMSK |= _BV(TOIE0);
TCNT2 = 150;
Time_Count = 0;
TCCR2 = _BV(CS22)|_BV(CS20); //CS02置1,|_BV(CS21)CS00,cs01置1 //1024分频
TIMSK |= _BV(TOIE2);
}
void main()
{
Init();
while(1)
{
Key_scan();
}
}
void TaskInTimer()
{
DJ_Run();
TaskInADC();
}
/*void TestInTimer()
{
if(flag_Time == 0 && flag_FTime == 0)
{
//PORTA |= (1 << PA1); //locked LED on进入锁定模式
flag_Locked = 0;
flag_Manual = 0;
flag_Follow = 0;
PORTC = 0xff;
flag_clockrise = 0;
flag_cclockrise = 0;
PORTA &= ~(1 << PA3); //auto LED off
PORTA &= ~(1 << PA2); //manual LED off
PORTA &= ~(1 << PA0); //motion LED off
PORTA &= ~(1 << PA4); //ADC off
PORTA |= (1 << PA1); //locked LED on进入锁定模式
}
}*/
……………………
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』