您的位置 首页 国产IC

PIC16F917 LED游侠灯程序

/*************PIC16F917单片机程序******************************//****************************************

/*************PIC16F917单片机程序******************************/

/*************************************************************/
/*****File Function : LED游侠灯程序 *****/
/*****Program Author : ZhengWen(ClimberWin) *****/
/*****MCU : PIC16F917 内部晶振 *****/
/*****Compile Date : 2010/08/16 *****/
/*****Edition Info : V1.0 *****/
/*************************************************************/
//引脚界说:PORTD=8LED,KEY=RB0
/*修正日期: */

/************************************/
#include#define uchar unsigned char
#define uint unsigned int
void speakertest(void);//蜂鸣器测验子程序
void keytest(void); //按键测验程序
void delayms(unsigned int count);
void PortInit(void);
void led_display(void);//LED显现子程序
#define KEY RB0
uchar led_num;//界说LED计数值存储地址

//数据形式 LED_DATA[0]显现次数 LED_DATA[1]显现速度 LED_DATA[2]-[18]显现数据
const uchar LED_DATA1[0x12]={0x03,0x32,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00};//弹跳灯
const uchar LED_DATA2[0x12]={0x05,0x78,0xC3,0x66,0x3C,0x18,0x18,0x3C,0x66,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x3C,0x66,0xC3};//双灯对撞形式
const uchar LED_DATA3[0x12]={0x05,0x50,0x00,0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81};//拉链形式
const uchar LED_DATA4[0x12]={0x03,0x32,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00};//LED灯柱
const uchar LED_DATA5[0x12]={0x03,0x64,0x55,0xaa,0x55,0xaa,0x155,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};//动感灯
const uchar LED_DATA6[0x12]={0x0A,0x28,0xFF,0x00,0xFF,0x00,0xAA,0x00,0x55,0x00,0x2A,0x00,0x54,0x28,0x00,0x28,0x00,0x10};//特别爆闪
const uchar LED_DATA7[0x12]={0x0A,0x32,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00};//爆闪

void led_display(void)
{
uchar i,j;

for(i=0;i {
for(j=2;j<18;j++)
{
PORTD=~LED_DATA1[j];
delayms(LED_DATA1[1]);
}
}

for(i=0;i { for(j=2;j<18;j++)
{PORTD=~LED_DATA2[j];delayms(LED_DATA2[1]);}
}

for(i=0;i { for(j=2;j<18;j++)
{PORTD=~LED_DATA3[j];delayms(LED_DATA3[1]);}
}

for(i=0;i { for(j=2;j<18;j++)
{PORTD=~LED_DATA4[j];delayms(LED_DATA4[1]);}
}

for(i=0;i { for(j=2;j<18;j++)
{PORTD=~LED_DATA5[j];delayms(LED_DATA5[1]);}
}

for(i=0;i { for(j=2;j<18;j++)
{PORTD=~LED_DATA6[j];delayms(LED_DATA6[1]);}
}

for(i=0;i { for(j=2;j<18;j++)
{PORTD=~LED_DATA7[j];delayms(LED_DATA7[1]);}
}

}

void Init(void)
{
PORTB = 0B00000000;
PORTD = 0B00000000;
TRISB = 0B00100001;//设置RB0为输入,作为按键口
TRISD = 0B00000000;//设置PORTD口为输出,作为LED显现口
led_num=EEPROM_READ(0); //从EEPROM中读取数据
PORTD=~led_num;
}

void keytest(void) //按键测验程序
{

/*********************************************/
if(KEY==0)
{
led_num++;
EEPROM_WRITE(0, led_num);//保存EEPROM数据
PORTD=~led_num;
//////////////////
while(KEY==0) //按键去抖
{ delayms(100);}
}
}
/*********************************************/
void delayms(unsigned int count)
{
uint i,j;
for(i=0;ifor(j=0;j<120;j++);
}
/*********************************************/

////////////主程序/////////////////////////
int main (void)
{
Init();

while(1)
{
//keytest();
led_display();//调用LED显现子程序
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/bandaoti/ic/267284.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部