单片机系列(一)

     好久没玩单片机了,先前零散学了点,现在想系统的学一遍,

动手写程序,刚好老早就买了的开发板( 强联的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;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值