完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "reg51.h" typedef unsigned char BYTE; typedef unsigned int WORD; //----------------------------------------------- /* define constants */ #define FOSC 11059200L #define T1MS (65536-FOSC/12/1000) //1ms timer calculation method in 12T mode /* define SFR */ ***it TEST_LED = P1^0; //work LED, flash once per second ***it pwm1 = P1^1; ***it pwm2 = P1^2; ***it pwm3 = P1^3; ***it pwm4 = P1^4; ***it k1=P1^5; ***it k2=P1^6; ***it k3=P1^7; ***it k4=P2^0; /* define variables */ WORD count; //1000 times counter WORD a,b,c; WORD time; WORD p1,p2,p3,p4; //----------------------------------------------- /* Timer0 interrupt routine */ void tm0_isr() interrupt 1 using 1 { TL0 = T1MS; //reload timer0 low byte TH0 = T1MS >> 8; //reload timer0 high byte if (count++ == 100) //1ms * 1000 -> 1s { count = 0; //reset counter TEST_LED = ! TEST_LED; //work LED flash } if (count<=p1) { pwm1=0; } else{pwm1=1;} if (count<=p2) { pwm2=0; } else{pwm2=1;} if (count<=p3) { pwm3=0; } else{pwm3=1;} if (count<=p4) { pwm4=0; } else{pwm4=1;} //----------------------------------------------- /* main program */ void main() { while (1){ if (k1==0) { for(a=0;a++;a<10000) { if(a<5000) { if(k1==1) { for(b=0;b++;b<10000) { if(k1==0) { p1=80; p2=60; p3=90; p4=80; TMOD = 0x01; //set timer0 as mode1 (16-bit) TL0 = T1MS; //initial timer0 low byte TH0 = T1MS >> 8; //initial timer0 high byte TR0 = 1; //timer0 start running ET0 = 1; //enable timer0 interrupt EA = 1; //open global interrupt switch count = 0; //initial counter b=10000; a=10000; } else { a=10000; b=10000; } } } } if(a>4999) { if(k3==0&&k1==0) { p1=100; p2=60; p3=90; p4=80; TMOD = 0x01; //set timer0 as mode1 (16-bit) TL0 = T1MS; //initial timer0 low byte TH0 = T1MS >> 8; //initial timer0 high byte TR0 = 1; //timer0 start running ET0 = 1; //enable timer0 interrupt EA = 1; //open global interrupt switch count = 0; //initial counter } else { if(k1==0) { p1=100; p2=80; p3=80; p4=100; TMOD = 0x01; //set timer0 as mode1 (16-bit) TL0 = T1MS; //initial timer0 low byte TH0 = T1MS >> 8; //initial timer0 high byte TR0 = 1; //timer0 start running ET0 = 1; //enable timer0 interrupt EA = 1; //open global interrupt switch count = 0; //initial counter } } } } if (k3==0) { p1=100; p2=0; p3=0; p4=100; TMOD = 0x01; //set timer0 as mode1 (16-bit) TL0 = T1MS; //initial timer0 low byte TH0 = T1MS >> 8; //initial timer0 high byte TR0 = 1; //timer0 start running ET0 = 1; //enable timer0 interrupt EA = 1; //open global interrupt switch count = 0; //initial counter } else { p1=100; p2=0; p3=0; p4=0;TMOD = 0x01; //set timer0 as mode1 (16-bit) TL0 = T1MS; //initial timer0 low byte TH0 = T1MS >> 8; //initial timer0 high byte TR0 = 1; //timer0 start running ET0 = 1; //enable timer0 interrupt EA = 1; //open global interrupt switch count = 0; //initial counter } } else { if (k2==0) { p1=50; p2=100; p3=0; p4=0; TMOD = 0x01; //set timer0 as mode1 (16-bit) TL0 = T1MS; //initial timer0 low byte TH0 = T1MS >> 8; //initial timer0 high byte TR0 = 1; //timer0 start running ET0 = 1; //enable timer0 interrupt EA = 1; //open global interrupt switch count = 0; //initial counter } else { if (k3==0) { p1=0; p1=40; p1=100; p1=0; TMOD = 0x01; //set timer0 as mode1 (16-bit) TL0 = T1MS; //initial timer0 low byte TH0 = T1MS >> 8; //initial timer0 high byte TR0 = 1; //timer0 start running ET0 = 1; //enable timer0 interrupt EA = 1; //open global interrupt switch count = 0; //initial counter } else { if (k4==0) { p1=0; p2=30; p3=0; p4=100; TMOD = 0x01; //set timer0 as mode1 (16-bit) TL0 = T1MS; //initial timer0 low byte TH0 = T1MS >> 8; //initial timer0 high byte TR0 = 1; //timer0 start running ET0 = 1; //enable timer0 interrupt EA = 1; //open global interrupt switch count = 0; //initial counter } } } } } } //loop } |
|
相关推荐
2个回答
|
|
是不是少加了头文件
|
|
|
|
问题出在hanjia.c你这个是main.c
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
690 浏览 0 评论
735 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
624 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
1099 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
1092 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11793 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 03:12 , Processed in 0.612574 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号