以下是软件仿真的结果:
以下是程序:
- /*
- * GccApplication10.c
- *
- * Created: 2014-9-1 12:07:23
- * Author: Administrator
- */
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #define uchar unsigned char
- #define uint unsigned int
- //定义按钮及LED与端口的连接
- //#define button1 PIND.2
- //#define button2 PIND.3
- //#define speaker PORTD.0
- #define redLED1 0//PORTC.0
- #define blueLED1 1//PORTC.1
- #define greenLED1 2//PORTC.2
- #define yellowLED1 3//PORTC.3
- #define redLED2 4//PORTC.4
- #define blueLED2 5//PORTC.5
- #define greenLED2 6//PORTC.6
- #define yellowLED2 7//PORTC.7
- uint i,a=0;
- uchar tab2[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F, //正向流水灯
- 0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF, //反向流水灯
- 0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F, //正向流水灯
- 0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF}; //反向流水灯
- //interrupt [TIM0_OVF] void timer0_ovf_isr(void)
- ISR(TIMER0_OVF_vect)
- {
- a++;
- TCNT0=0x00;
- }
- int main(void)
- {
- //uchar k;
- DDRC=0xFF;
- PORTC=0xFF;
- TCCR0=0x05; //WGM01=0 WGM00=0选择普通模式;COM01=0 COM00使PB3为通用I/O(OC0不与引脚相连)CS02=1 CS01=0 CS01=1选择1024分频
- TCNT0=0x00;
- OCR0=0x00;
- TIMSK=0x01;
- //#asm("sei")
- sei();
- while(1)
- {
- for(i=0;i<23;)
- {
- if(a==30)
- {
- PORTC=tab2[i];
- a=0;
- i++;
- }
- else
- {;}
- }
- }
- }
|