/* * GccApplication1.c * * Created: 2014-10-23 18:57:04 * Author: Administrator */ #define F_CPU 4000000UL #include <avr/io.h> #include <avr/interrupt.h> #include <stdint.h> #include <util/delay.h> #define RED_EW_ON() PORTC |= (1<<0) #define YELLOW_EW_ON() PORTC |= (1<<1) #define GREEN_EW_ON() PORTC |= (1<<2) #define RED_EW_OFF() PORTC &= ~(1<<0) #define YELLOW_EW_OFF() PORTC &= ~(1<<1) #define GREEN_EW_OFF() PORTC &= ~(1<<2) #define RED_SN_ON() PORTC |= (1<<3) #define YELLOE_SN_ON() PORTC |= (1<<4) #define GREEN_SN_ON() PORTC |= (1<<5) #define RED_SN_OFF() PORTC &=~(1<<3) #define YELLOW_SN_OFF() PORTC |=~(1<<4) #define GREEN_SN_OFF() PORTC &= ~(1<<5) #define YELLOW_EW_BLINK() PORTC^=0x02 #define YELLOW_SN_BLINK() PORTC^=0x10 #define BEEP() (PORTB ^=0x01) uint8_t Time_Count = 0,Flash_Count = 0,Operation_Type = 1; int main(void) { DDRB = 0xFF; PORTC = 0xFF; DDRC = 0xFF; PORTC = 0x00; TCCR1B = 0x03; //T1 分频 64 TCNT1 = 65536 - F_CPU/64.0 *0.5; sei(); while(1) { //TODO:: Please write your application code } } void Yellow_Light_Alarm() { uint8_t i; for(i=0;i<100;i++) { BEEP();_delay_us(380); } } ISR(TIMER1_OVF_vect) { TCNT1 = 65536 - F_CPU/64.0*0.5; //重装定时值 switch(Operation_Type) { case 1: RED_EW_OFF(); YELLOW_EW_OFF(); GREEN_EW_ON(); RED_SN_ON(); YELLOW_SN_OFF(); GREEN_SN_OFF(); if(++Time_Count != 10) return; Time_Count = 0; Operation_Type = 2; break; case 2: Yellow_Light_Alarm(); GREEN_EW_OFF(); YELLOW_EW_BLINK(); if(++Flash_Count != 10) return; Flash_Count = 0; Operation_Type = 3; break; case 3: RED_EW_ON(); YELLOW_EW_OFF();GREEN_EW_OFF(); RED_SN_OFF(); YELLOW_SN_OFF();GREEN_SN_ON(); if(++Time_Count != 10)return; Time_Count = 0; Operation_Type = 4; break; case 4: Yellow_Light_Alarm(); GREEN_SN_OFF(); YELLOW_SN_BLINK(); if(++Flash_Count != 10)return; Flash_Count = 0; Operation_Type = 1; } }
您需要 登录 才可以下载或查看,没有账号?注册
举报
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
等级类勋章
发帖类勋章
时间类勋章
人才类勋章
2403
6994
68
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号