该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
在学校的时候就玩了,根本没怎么用心学,现在只好自学,今天是起步,做了个简单的流水灯程序,记录一下,同时鞭策自己。
开发板是KingST的,编程软件是keil,下载时STC-ISP,下面是程序
#include
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
void main()
{
/*方法一:流水灯左移
unsigned int i=0;
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
while(1)
{
P0 = 0xFE;
for(i=0;i<30000;i++);
P0 = 0xFD;
for(i=0;i<30000;i++);
P0 = 0xFB;
for(i=0;i<30000;i++);
P0 = 0xF7;
for(i=0;i<30000;i++);
P0 = 0xEF;
for(i=0;i<30000;i++);
P0 = 0xDF;
for(i=0;i<30000;i++);
P0 = 0xBF;
for(i=0;i<30000;i++);
P0 = 0x7F;
for(i=0;i<20000;i++);
}*/
/*方法二:流水灯左移
unsigned int i = 0;
unsigned char cnt = 0;
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
while(1)
{
P0 = ~(0x01 << cnt);
for(i = 0;i < 30000;i++);
cnt++;
if(cnt>=8)
cnt = 0;
}
*/
/*方法二:流水灯右移
unsigned int i = 0;
unsigned char cnt = 0;
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
while(1)
{
P0 =~(0x80>>cnt);
for(i=0;i<30000;i++);
cnt++;
if(cnt>=8)
cnt = 0;
}
*/
/*左右循环流水灯
unsigned int i = 0;
unsigned char cnt;
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
while(1)
{
for(cnt =0 ;cnt < 8;cnt++)
{
P0 = ~(0x01 << cnt); //左移部分
for(i = 0;i < 30000;i++);
}
for(cnt =0 ;cnt < 8;cnt++)
{
P0 =~(0x80>>cnt); //右移部分
for(i=0;i<30000;i++);
}
}
*/
}