呼吸灯的c51程序
时间:08-24
来源:互联网
点击:
型号只能同时控制两路。在网上找到有控制16路的,目前还看不懂。
看来流星灯的制作,还是有点小困难的。还得继续研究。
下面是两路的程序
#include reg52.h>//设置sfrsfr CCON = 0xD8;sfr CMOD = 0xD9;sfr CL = 0xE9;sfr CH = 0xF9;sfr CCAP0L = 0xEA;sfr CCAP0H = 0xFA;sfr CCAP1L = 0xFB;sfr CCAP1H = 0xFB;sfr CCAPM0 = 0xDA;sfr CCAPM1 = 0xDB;sbit CR = 0xDE;void PWM_init(void){CMOD = 0x02;//设置PCA定时器CL = 0x00;CH = 0x00;//PWM0的设置CCAPM0 = 0x42;CCAP0L = 0x00;CCAP0H = 0x00;//PWM1的设置CCAPM1 = 0x42;CCAP0L = 0x00;CCAP0H = 0x00;CR = 1;//启动PCA定时器}//设置PWM0的参数void PWM0_set(unsigned char a){CCAP0L = a;CCAP0H = a;}//设置PWM1的参数void PWM1_set(unsigned char a){CCAP1L = a;CCAP1H = a;}void delay (unsigned int a){ // 0.1ms延时程序(12MHz 10倍于51单片机速度时)unsigned char i;while( --a != 0){for(i = 0; i 12; i++);} }void main(void){unsigned int i;PWM_init();//PWM初始化PWM0_set(0x00);//设置PWM0占空比PWM1_set(0x00);//设置PWM1占空比while(1){for(i = 0;i 256;i++){PWM0_set(i);PWM1_set(256 - i);delay(100);}for(i = 256;i > 0;i--){PWM0_set(i);PWM1_set(256 - i);delay(100);}}}
- 非常短的呼吸灯程序(11-25)
- 在C51程序中嵌入汇编(11-27)
- Keil C51程序调试过程(11-17)
- 单片机驱动蜂鸣器C51程序(12-05)
- 一个简单的流水灯c51程序(11-15)
- 单片机控制交通灯c51程序(11-15)