|
wujinlin(VIP会员)
头衔:社区公民
帮派:无帮无派
帖数:26
金钱:380
积分:112
注册时间:2020/12/30
|
单片机电子灯箱控制器源码
/******************************************************** *描述:8组小灯正转10圈,反转10圈,常亮5秒,闪烁3秒,依次循环 ********************************************************/ #include "stc15w.h" #include "intrins.h" //包含左移和右移指令 #include "string.h" //字符串 #include "stdio.h" //标准输入输出 /******************************************************************************* * 文件名:未定义 * 描 述: * 功 能: * 作 者: * 版本号:1.0.1(2017.05.23) *******************************************************************************/ bit flag500ms = 0;//500ms翻转一次 sbit LED0 = P1^0;// sbit LED1 = P1^1; sbit LED2 = P1^2; sbit LED3 = P1^3; sbit LED4 = P1^4; sbit LED5 = P3^2; sbit LED6 = P0^0; sbit LED7 = P0^1; sbit DATA0 = P2^0;// sbit DATA1 = P2^1;// sbit DATA2 = P2^2;// sbit DATA3 = P2^3;// sbit DATA4 = P2^4;// sbit DATA5 = P2^5;// sbit DATA6 = P2^6;// sbit DATA7 = P2^7;// typedef unsigned char uint8;//0-255 typedef unsigned int uint16;//0-65535 typedef unsigned long uint32;//0-65535*65535 /******************************************************************************* * 文件名:函数前置声明 *******************************************************************************/ void Bsp_Power_Init(void); void Delay500ms(); //@11.0592MHz void Timer0Init(void); //1毫秒@11.0592MHz /******************************************************************************* * 文件名:主循环入口 *******************************************************************************/ void main(void) { uint8 i = 0; Bsp_Power_Init();//LED端口初始化 Timer0Init(); //定时器0初始化函数 LED0 = 1; while(1) { for(i = 0; i < 3; i++) { DATA0 = 0; Delay500ms(); DATA0 = 1; Delay500ms(); DATA1 = 0; Delay500ms(); DATA1 = 1; Delay500ms(); DATA2 = 0; Delay500ms(); DATA2 = 1; Delay500ms(); } for(i = 0; i < 3; i++) { DATA2 = 0; Delay500ms(); DATA2 = 1; Delay500ms(); DATA1 = 0; Delay500ms(); DATA1 = 1; Delay500ms(); DATA0 = 0; Delay500ms(); DATA0 = 1; Delay500ms(); } for(i = 0; i < 3; i++) { DATA2 = 0; DATA1 = 0; DATA0 = 0; Delay500ms(); DATA2 = 1; DATA1 = 1; DATA0 = 1; Delay500ms(); } } } /******************************************************************************* * 文件名:void Bsp_Power_Init() * 描 述: 数码管上电显示 * 功 能:编程模块化 *******************************************************************************/ void Bsp_Power_Init(void) { P0M1 = 0xFC; P0M0 = 0X03; P0 = 0X00; P1M1 = 0xE0; P1M0 = 0X1F; P1 = 0X00; //P2口开漏输出 P2M1 = 0XFF; P2M0 = 0XFF; P2 = 0Xff; // //P54,P55口为推挽输出 P5M1 = 0X00; P5M0 = 0X00; P5 = 0xFF; //P37,P36,3.2,P3.3 P3.4口为推挽输出 P3M1 = 0X00; P3M0 = 0XFC; P3 = 0X23; } /******************************************************************************* * 文件名:void Delay500ms() //@11.0592MHz * 描 述: 普通延时函数 * 功 能:编程模块化 *******************************************************************************/ void Delay500ms() //@11.0592MHz { unsigned char i, j, k; _nop_(); _nop_(); i = 22; j = 3; k = 227; do { do { while (--k); } while (--j); } while (--i); } /******************************************************************************* * 文件名:void Timer0Init(void) * 描 述: 定时器0配置 * 功 能:编程模块化 *******************************************************************************/ void Timer0Init(void) //1毫秒@11.0592MHz { AUXR |= 0x80; //定时器时钟1T模式 TMOD &= 0xF0; //设置定时器模式 1111_ TMOD |= 0X01; //16位模式,不可重装 // TL0 = 0xCD; //设置定时初值 // TH0 = 0xD4; //设置定时初值 TL0 = (65535 - 11059) % 256; //设置定时初值 TH0 = (65535 - 11059) / 256; //设置定时初值 ET0 = 1; //打开定时器0中断使能 TR0 = 1; //定时器0开始计时 EA = 1; //打开总中断使能 } void TIME0_IRQ_Handler() interrupt 1 { static uint16 tmr10ms = 0; static uint8 tmr3s = 0; static uint8 tmr5s = 0; static uint8 a = 0; TL0 = (65535 - 11059) % 256; //设置定时初值 TH0 = (65535 - 11059) / 256; //设置定时初值 //1ms溢出一次 tmr10ms++; if(a) { if(tmr10ms >= 500) { tmr10ms = 0; DATA4 = ~DATA4;//500ms闪烁依次 tmr3s++; } if(tmr3s >= 6) { tmr3s = 0; //闪烁3次 a = 0; } } else { if(tmr10ms >= 500) { tmr10ms = 0; DATA4 = 0; //亮5秒 tmr5s++; } if(tmr5s >= 10) { tmr5s = 0; a = 1; } } } 这家伙很懒,什么也没有留下! |
|
等级: |
2020/12/30 21:31:02
|