中级会员
- 积分
- 309
- 威望
- 264
- 贡献
- 39
- 兑换币
- 18
- 注册时间
- 2010-1-14
- 在线时间
- 3 小时
|
/*****************************************************
This program was produced by the
CodeWizardAVR V1.25.6c Professional
Automatic Program Generator
?Copyright 1998-2006 Pavel Haiduc, HP vula_adcfoTech s.r.l.
http://www.hp vula_adcfotech.com
Project : 小车
Version : 0.00
Date : 2007-8-30
Author : momo
Company : zhong bei da xue
Comments:
Chip type : ATmega16L
Program type : Application
Clock frequency : 1.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include "config.h"
#define startCPA TCCR1A|=0X40
#define startCPB TCCR1A|=0X10
#define stopCPA TCCR1A&=0XBF
#define stopCPB TCCR1A&=0XEF
#define MBgo PORTD.0=0
#define MBback PORTD.0=1
#define MAgo PORTD.1=0
#define MAback PORTD.1=1
/****************************************************
全局变量声明
*****************************************************/
volatile unsigned char flage=0X00;
volatile unsigned char Timer[3]={0,0,0};
volatile unsigned char write;
volatile unsigned char BalanceTime=0;
unsigned char balan =1;
unsigned char vula_adc;
unsigned char ad;
flash char *step[4]={ "stepA","stepB","stepC","back " } ;
flash char *mode[2]={"normal","advanc"};
/******************************************************
系统中断 (显示,蜂鸣)
*******************************************************/
interrupt [TIM0_COMP ] void tim0_comp_isr(void)
{
static unsigned char buzz;
switch ( flage )
{
case 0X04:
Timer[0]=Read_sec( );
if( Timer[0]==Timer[2] )
;
else
{
BalanceTime++;
LCD_write_char( 13 , 1 , ( BalanceTime%10)+'0' );
LCD_write_char( 12 , 1 , ( BalanceTime/10)+'0' );
Timer[2]=Timer[0] ;
}
goto j1;
break;
case 0X84:
Timer[0]=Read_sec( );
if( Timer[0]==Timer[2] )
;
else
{
BalanceTime++;
LCD_write_char( 13 , 1 , ( BalanceTime%10)+'0' );
LCD_write_char( 12 , 1 , ( BalanceTime/10)+'0' );
Timer[2]=Timer[0] ;
}
case 0X80:
if( (++buzz) == 10 )
{
buzz=0;
PORTC.2=1;
flage -=0x80;
}
j1:
case 0X00:
Timer[0]=Read_sec( );
write=Timer[0];
LCD_write_char( 11 , 0 , (write& 0x0f)+ '0' );
LCD_write_char( 10 , 0 , ( (write>>4)&0x07) + '0' );
Timer[1]=Read_miu( );
write=Timer[1];
LCD_write_char( 4 , 0 , (write& 0x0f)+'0');
break;
default: break;
}
}
/*****************************************************************************
系统中断T2 (寻线校正)
*****************************************************************************/
interrupt [TIM2_COMP ] void tim2_comp_isr(void)
{
if(PORTD.1==1)
{
if(PIND.6==1)
startCPA;
else
stopCPA;
if(PIND.7==1)
startCPB;
else
stopCPB;
}
else
{
if(PIND.2==1)
startCPA;
else
stopCPA;
if(PIND.3==1)
startCPB;
else
stopCPB;
}
}
unsigned char get_ad(void) {
unsigned char i;
ADMUX = 0x60; /*基准AVCC、左对齐、通道0*/
ADCSRA = 0xC2; /*使能、开启、4分频*/
while(!(ADCSRA & (1 << ADIF))); /*等待*/
i = ADCH;
ADCSRA &= ~(1 << ADIF); /*清标志*/
ADCSRA &= ~(1 << ADEN); /*关闭转换*/
return i;
}
void beep( void )
{
PORTC.2=0;
delay_ms(500);
PORTC.2=1;
}
void Findbenlen( void )
{
balan=1;
do
{
if( get_ad( ) <=0X79 ) //0x7d(yuan shi) 0X7E bux vula_adcg
{
MBgo ;
MAgo ;
startCPA ;
startCPB ;
delay_ms(200);
stopCPA ;
stopCPB ;
}
delay_ms(200);
if( get_ad( ) >=0X81 ) //0x7d(yuan shi) 0X7E bux vula_adcg
{
MBback ;
MAback ;
startCPA ;
startCPB ;
delay_ms(200);
stopCPA ;
stopCPB ;
}
delay_ms(400);
if( get_ad( ) >= 0X84) //0x82
{
MBback ;
MAback ;
startCPA ;
startCPB ;
delay_ms(200);
stopCPA ;
stopCPB ;
}
delay_ms(400);
if( get_ad( ) <=0X82 ) //0x7d(yuan shi) 0X7E bux vula_adcg
{
MBgo ;
MAgo ;
startCPA ;
startCPB ;
delay_ms(200);
stopCPA ;
stopCPB ;
}
delay_ms(400);
ad=get_ad( );
if( ad < 0X82 && ad > 0X79 )
balan=0;
} while(balan);
balan=1;
do
{
if( get_ad( ) <=0X7B ) //0x7d(yuan shi) 0X7E bux vula_adcg
{
MBgo ;
MAgo ;
startCPA ;
startCPB ;
delay_ms(150);
stopCPA ;
stopCPB ;
}
if( get_ad( ) >= 0X82) //0x82
{
MBback ;
MAback ;
startCPA ;
startCPB ;
delay_ms(150);
stopCPA ;
stopCPB ;
}
delay_ms(2000);
ad=get_ad( );
if( ad < 0X82 && ad > 0X7B )
balan=0;
} while(balan);
}
unsigned char SelectMode ( void )
{
unsigned char temp=0;
LCD_write_str( 0 , 0 ,"pass START key");
LCD_write_str( 0 , 1 ,"zhong bei da xue ");
//do
//{
//delay_ms( 250 );
//}
while( PINC.6 ==1 );
while(PINC.6 ==0);
LCD_clear( );
LCD_write_str( 0 , 0 ,"mode:");
LCD_write_str( 0 , 1 ,"select mode");
LCD_write_str( 6 , 0 ,mode[0]);
delay_ms( 1000 );
do
{
if( PINC.7==0 )
{
while(PINC.7==0);
++temp;
if(temp==2)
temp=0;
LCD_write_str( 6 , 0 ,mode[temp]);
}
//delay_ms( 200 );
}
while(PINC.6==1);
while(PINC.6==0);
LCD_clear( );
return(temp);
}
/*******************************************************
基本要求部分
*******************************************************/
void nomal ( void )
{
/*****************************************************
显示时钟,初始设置
*****************************************************/
LCD_write_str( 0 , 0 ,"minc: sec: ");
LCD_write_str( 0 , 1 , step[0] );
delay_ms(1000);
PORTC.2=0; |
|