?? radar oven00.c
字號:
#define MAIN_INCLUDE
//#define HT1621
//#define DEBUG_WriteDumy
//#define DEBUG_232
#include "radar oven00.h"
void main(void)
{
unsigned short timedata,td,lendata,basicwidth,tempdata;
unsigned char i,j,disp,fg,txtime,txfg,zerofg,shortflag,counter;
unsigned short basicwidths[5];
signed short tempp;
Flag_comm.timerBint_flag=0;
Flag_comm.Lowbatt_flag=0;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 &= ~XT2OFF; // ACLK = LFXT1 = HF XTAL
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
Delayms(1);
}
while ((IFG1 & OFIFG) == OFIFG); // OSCFault flag still set?
BCSCTL2 |= SELM1+SELS; // MCLK & SMCLK = LFXT2 (safe)
P1SEL = 0;
P2DIR &= ~BIT1;
P2OUT &= ~BIT1;
P1DIR |= BIT3+BIT4+BIT2;
P1OUT &= ~(BIT3+BIT4+BIT2);
ME1 |= UTXE0; // Enable USART0 TXD/RXD
//IE1 |= URXIE0; // Enable USART0 RX interrupt
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
P3DIR |= 0x10; // P3.4 output direction
intialization_ht1621();
ht1621_ramdump(0xff);
for(i=10;i>0;i--)
{
Delayms(500);
P1OUT ^= BIT3+BIT4+BIT2;
}
ht1621_ramdump(0);
tempp=-2;
UCTL0 = CHAR; // 8-bit character
UTCTL0 = SSEL1; // UCLK = SMCLK 8000000
UBR00 = 34; // 4000000/115200
UBR10 = 0; //
UMCTL0 = 0xbb; // modulation
TBCCR0 =32768/10-1; // 1 hz interrupt
TBCTL |=TBSSEL0 + TBCLR + TBIE + MC0;
TACTL |=TASSEL1 + TACLR + ID1 + ID0;
TACCR0 =65535;
disp=0;
basicwidth=0;
txtime=6;
shortflag=0;
counter=0;
basicwidths[0]=0;
basicwidths[1]=0;
basicwidths[2]=0;
basicwidths[3]=0;
basicwidths[4]=0;
tempp=abs(tempp);
ht1621_ramdump(tempp);
_EINT(); // Enable interrupts
for (;;)
{
if(Flag_comm.timerBint_flag==1)
{
Flag_comm.timerBint_flag=0;
//P1OUT |= BIT7;
TACTL |= MC0+TACLR;
P2DIR |= BIT1;
Delayms(4);
P2DIR &= ~BIT1;
//P1OUT &= ~BIT7;
Delayms(1);
//timedata=TAR;
//ht1621_displayInt(1,timedata);
fg=0;
td=0;
timedata=0;
while(1)
{
zerofg=0;
if((P2IN & BIT1)==BIT1 && fg==0)
{
fg=1;
basicwidth=TAR-400;
}
//lendata=0;
if((P2IN & BIT1)==0 && fg==1 && shortflag==0)
{
td=TAR;
for (j=20;j>0;j--);
if((P2IN & BIT1)==0)
{
TACTL &= ~MC0;
timedata=td;
//lendata=(unsigned short)(((unsigned long)timedata*346)/20000);
zerofg=1;
break;
}
}
if(TAR>27000)
{
TACTL &= ~MC0;
if(timedata==0)
timedata=0xffff;
break;
}
}
TACTL &= ~MC0;
Timedistance+=timedata;
basicwidths[counter]=basicwidth;
if(++counter>4)
{
counter=0;
tempdata=0;
basicwidth=(basicwidths[0]+basicwidths[1]+basicwidths[2]+basicwidths[3]+basicwidths[4])/5;
for(i=0;i<5;i++)
{
if(basicwidth>basicwidths[i])
tempdata+=basicwidth-basicwidths[i];
else
tempdata+=basicwidths[i]-basicwidth;
}
tempdata=tempdata*100/basicwidth;
if(tempdata>15)basicwidth=2000;
basicwidths[0]=0;
basicwidths[1]=0;
basicwidths[2]=0;
basicwidths[3]=0;
basicwidths[4]=0;
Timedistance/=5;
if(basicwidth>1200)lendata=0;
else
lendata=(unsigned short)(((unsigned long)Timedistance*346)/20000);
if(lendata>40)P1OUT &= ~BIT2;
else P1OUT |= BIT2;
if(lendata>50)P1OUT &= ~BIT3;
else P1OUT |= BIT3;
if(lendata>60)P1OUT &= ~BIT4;
else P1OUT |= BIT4;
ht1621_displayChar(1,lendata);
ht1621_displayChar(4,basicwidth/10);
Timedistance=0;
if(Flag_comm.timerBint_flag==1)
Flag_comm.timerBint_flag=0;
}
}
while ((IFG1 & UTXIFG0) == 0); // USART0 TX buffer ready?
_NOP(); // Required only for C-spy
}
}
void Delayms(unsigned short n)
{
register unsigned short j;
for(;n>0;n--)
{
for (j=130;j>0;j--)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -