8彩燈閃爍的程序已經寫好,pwm脈寬調制的程序不會寫,有沒有誰能幫忙看一下。
- #define F_CPU 4000000UL
- #include <avr/io.h>
- #include <util/delay.h>
- #define INT8U unsigned char
- const INT8U Pattern_P0[]=
- {
- 0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0xff,0x00,0xff,0x7e,0xbd,0xdb,0xe7,0xc3,0x81,0x00
- };
- const INT8U Pattern_P1[]=
- {
- 0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0xff,0x00,0xff,0x7e,0xbd,0xdb,0xe7,0xc3,0x81,0x00
- };
- int main(void)
- {
- INT8U i;
- DDRC=0XFF; PORTC=0XFF; //配置端口
- DDRD=0XFF; PORTD=0XFF;
- while (1)
- {
- for (i=0;i<19;i++) //循環顯示全部花樣字節
- {
- PORTC= Pattern_P0[i]; //第一組發送給PORTC端口
- PORTD= Pattern_P1[i]; //都二組發送給PORTD端口
- _delay_ms(80);
- }
- }
- }
復制代碼
|