好久没玩单片机了,先前零散学了点,现在想系统的学一遍,
动手写程序,刚好老早就买了的开发板( 强联的WS803A
http://www.qlmcu.com/shop_kfgj/ws803a.asp)又利用
起来了,这次准备从最简单的开始,好好的玩一遍,呵呵……说干就干了,希望自
己能坚持下去。这是昨天写的一个跑马灯程序,没什么新意,只是练练手,不足之处还望
大家不惜赐教。小弟先行谢过!!!
说真的c语言是从大一就开始学的,还真没掌握多少
精华。下面的程序可能也是错误百出,虽然勉强通过了编译。
//$$$$ $$$$$$$$$$$$$$$$$$$$//
// FileName: Led.c ||
// Function: 8 Leds light ||
// Author : Softstone ||
// Time : 2007/04/19 ||
//$$$$$$$$$$$$$$$$$$$$$$$$$//
#include <reg51.h>
#define uchar unsigned char
#define Led P0
sbit LedCs=P3^7;
void Delay(uchar);
void LedLeft();
void LedRight();
void LedFlash();
void LedCross();
void main()
{
while(1)
{
LedCs=1;
LedRight();
LedLeft();
Delay(1000);
LedCross();
Delay(1000);
LedFlash();
LedCs=1;
}
}
//***************************//
// Led run from left to right ||
//***************************//
void LedRight()
{
uchar temp;
uchar m,n,i;
LedCs=0;
temp=0xfe;
for(i=0;i<8;i++)
{
Delay(100);
Led=temp;
m=temp<<1;
n=temp>>7;
temp=m|n;
Delay(100);
}
}
//*****************************//
// Led run from right to left ||
//*****************************//
void LedLeft()
{
uchar temp;
uchar m,n,i;
LedCs=0;
temp=0x7f;
for(i=0;i<8;i++)
{
Delay(100);
Led=temp;
m=temp>>1;
n=temp<<7;
temp=m|n;
Delay(100);
}
}
//**************************//
// Led flash four times ||
//**************************//
void LedFlash()
{
uchar i;
for(i=0;i<4;i++)
{
LedCs=0;
Led=0;
Delay(500);
Led=0xff;
Delay(500);
}
}
//****************************//
// Led lights across four times ||
//****************************//
void LedCross()
{
uchar i;
for(i=0;i<4;i++)
{
LedCs=0;
Led=0xaa;
Delay(500);
Led=0x55;
Delay(500);
}
}
//*****************************//
// The delay function ||
//*********************** *****//
void Delay(uchar x)
{
uchar i;
while(x--)
for(i=0;i<125;i++)
continue;
}