📄 cardtimer.cpp.bak
字号:
//cardTimer.cpp : source file for the card Timers
//
#include "card.h"
#include "cardTimer.h"
/////////////////////////////////////////////////////////////////////////////
//cardTimer
/////遥控相关寄存器定义
volatile unsigned char IrDataHigh=0;
volatile unsigned char IrDataLow=0;
volatile unsigned int NoIrReviceTime=0;
////////蓝牙发送相关寄存器
volatile unsigned char BtTxData[BT_TX_BUFF_LENG];
volatile unsigned char BtTxDataCount=0;
volatile unsigned char BtTxDataStart=0;
unsigned char BtStartBit=0;
unsigned char BtTxOver=0;
unsigned char DataBitCount=0;
//////蓝牙接收
volatile unsigned char BtRxData[BT_RX_BUFF_LENG];
volatile unsigned char BtRxOk=0;
volatile unsigned char BtRxDataBuff[20];
volatile unsigned char BtRxCount=0;
volatile unsigned char BtDataBuff=0;
unsigned char RxDataBitCount=0;
unsigned char RxDataReviceOk=0;
unsigned char RxPackcount=0;
volatile unsigned char BtRxDataPackOver=1;
unsigned int T10msCount=0;
unsigned char T100usCount=0;
volatile unsigned char B_10ms=0;
//////
void timers_init(void)
{
#if defined(ATMEG8)
//{{WIZARD_MAP(Timers)
// Timer/Counter0 Clock source: System Clock
// Timer/Counter0 Clock value: 4000.000kHz
// Timer/Counter0 Mode: Normal
// Timer/Counter0 Output: A: Disconnected, B: Disconnected
OCR0A = 0x04;
OCR0B = 0x04;
TCNT0 = 0xfc;
TCCR0A = 0x00;
TCCR0B = 0x00;
// Timer/Counter1 Clock source: System Clock
// Timer/Counter1 Clock value: 500.000kHz
// Timer/Counter1 Mode: Normal
// Timer/Counter1 Output: A: Disconnected, B: Disconnected
OCR1A = 0x1388;
OCR1B = 0x1388;
TCNT1 = 0xec78;
TCCR1A = 0x00;
TCCR1B = 0x02;
TCCR1C = 0x01;
// Timer/Counter2 Clock source: System Clock
// Timer/Counter2 Clock value: Stopped
// Timer/Counter2 Mode: Normal
// Timer/Counter2 Output: A: Disconnected, B: Disconnected
ASSR = 0x00;
OCR2A = 0x34;
OCR2B = 0x34;
TCNT2 = 0xcc;
TCCR2A = 0x00;
TCCR2B = 0x00;//Timer2 stop
TIMSK0 = 0x02;
TIMSK1 = 0x01;
TIMSK2 = 0x00;
//}}WIZARD_MAP(Timers)
#endif
#if defined(ATMEG16)
//{{WIZARD_MAP(Timers)
// Timer/Counter0 Clock source: System Clock/8
// Timer/Counter0 Clock value:
// Timer/Counter0 Mode: CTC 100US
// Timer/Counter0 Output: A: Disconnected, B: Disconnected
OCR0=50;
TCNT0 =1;
TCCR0=0;//0x0A;
// Timer/Counter1 Clock source: System Clock/8
// Timer/Counter1 Clock value: 500.000kHz
// Timer/Counter1 Mode: Normal 10MS
// Timer/Counter1 Output: A: Disconnected, B: Disconnected
OCR1A = 0x1388;
OCR1B = 0x1388;
TCNT1 = 0xec78;
TCCR1A = 0x00;
TCCR1B =0x01; //0x02;
// Timer/Counter2 Clock source: System Clock
// Timer/Counter2 Clock value: 4000.000kHz
// Timer/Counter2 Mode: Normal 31US
// Timer/Counter2 Output: A: Disconnected, B: Disconnected
ASSR = 0x00;
OCR2 = 130;
TCNT2 = 138;
TCCR2 =0x01;
//TIMSK0 = 0x00;
//TIMSK1 = 0x01;
//TIMSK2 = 0x00;
TIMSK=0x44;//0x46; // Timer/Counter1, Overflow Interrupt Enable
// Timer/Counter2 OutputOverflow Interrupt Enable
//Timer/Counter0 Output Compare Match Interrupt Enable
//}}WIZARD_MAP(Timers)
#endif
}
////////
void IsrTxBluetooth(void)
{
IrDataHigh++;
IrDataLow++;
NoIrReviceTime++;
if(BtTxDataStart) //MCU发送蓝牙命令
{
if(!BtTxOver)
{
if(BtStartBit)
{
DataBitCount++;
if(DataBitCount<9)
{
BtTxData[BtTxDataCount]=BtTxData[BtTxDataCount]>>1;
if(BtTxData[BtTxDataCount]&0x80) //发送8位数据
PORTD|=BT_TX;
else
PORTD&=~BT_TX;
}
else
{
DataBitCount=0;
BtStartBit=0;
PORTD|=BT_TX; //发送停止位
BtTxOver=1;
}
}
else //发送起始位
{
PORTD&=~BT_TX;
BtStartBit=1;
}
}
else
{
BtTxOver=0;
}
}
}
///////////////
void T_10ms_delay(void)
{
//sei();
RxTimeOut++;
FastChangeTime++;
wStatusDelay++;
wStatusDelay1++;
wLedOffDelay++;
IpodPowerUpDelay++;
LCDFlashTime++;
B_10ms=1;
/*
if(LedWorkMode == LED_ON_DELAY)
{
if(wLedOffDelay > wLedTurnOnTime)
{
PORTC |= LED;
LedWorkMode = LED_OFF;
}
}
*/
PINBBuff = 0;
PINDBuff |= (PIND & AUDIO_DETECT); //音频检测开关
PINBBuff |= (PINB & BT_SWITCH_DETECT); //来电检测开关
PINBBuff |= (PINB & IPOD_POWER_UP_DETECT); //IPOD电源检测开关
ADMUX = 0x67;
ADCSRA |= 1 << ADSC;
ADCSRA |= 1 << ADIF;
}
///////////////
void IsrRxBluetooth(void)
{
BtRxCount++;
if(!BtRxDataPackOver)
{ if(BtRxFirstData) //是否为第一位数据
{
if(BtRxCount==5) //为启始位数据时计数5次
{
BtRxFirstData=0;
BtRxCount=0;
if(PIND&BT_RX)
BtDataBuff|=0x80;
}
}
else
{
if(BtRxCount==3) //数据位记数三次
{
BtRxCount=0;
RxDataBitCount++; //数据位数增加
BtDataBuff=BtDataBuff>>1;
if(PIND&BT_RX)
BtDataBuff|=0x80;
if(RxDataBitCount==7) //7位数据是否全部收到
{RxDataBitCount=0;
RxDataReviceOk=1;
BtRxFirstData=0;
}
}
}
//////
if(RxDataReviceOk)
{
RxDataReviceOk=0;
BtRxData[RxPackcount++]=BtDataBuff;
if(BtRxData[1]==RxPackcount-1) //数据包是否接收完成
{
RxPackcount=0;
BtRxDataPackOver=1;
}
}
}
}
/////////////
//ISR(SIG_OUTPUT_COMPARE0) //TIMER0 COPARE0中断遥控器接收计时
ISR(SIG_OUTPUT_COMPARE0)
{
IsrTxBluetooth();
if(T10msCount>=10)
{T10msCount=0;
T_10ms_delay();
}
}
/////////////
ISR(SIG_OVERFLOW1) //TIMER1中断数据时间延时
{
// Reinitialize Timer1's value
//TCNT1 = 0xec78;//10ms
// TODO: Add your code here
sei();
TCNT1=64830; //65275; //65180;//100us
IsrTxBluetooth();
T10msCount++;
if(T10msCount>=100)
{
T10msCount=0;
T_10ms_delay();
}
}
////////////////
ISR(SIG_OVERFLOW2) //MCU接收CUP_BLUETOOTH 数据传输 30us
{
//asm("wdr");
TCNT2 =40;//100;//170;//180;
//T100usCount++;
//T10msCount++;
IsrRxBluetooth();
/*
if(T100usCount>=3)
{
T100usCount=0;
IsrTxBluetooth();
}
if(T10msCount>=290)
{
T10msCount=0;
T_10ms_delay();
}
*/
/*
if(BTTxBitCount == 8)
{
PORTD |= BT_RX;
BTTxBitCount++;
}
else if(BTTxBitCount == 9)
{
BTTxBitCount = 0;
if(BTTxByteCount == 4)
{
TCCR2 = 0x00; //Timer 2 stop;
PORTD |= BT_RX;
}
else
{
BTTxByteCount++;
PORTD &= ~BT_RX;
}
}
else
{
if(BTTxBuff[BTTxByteCount] & 0x01)
{
PORTD |= BT_RX;
}
else
{
PORTD &= ~BT_RX;
}
BTTxBuff[BTTxByteCount] >>= 1;
BTTxBitCount++;
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -