PIC16F917 LED游侠灯程序
/*************************************************************/
/*****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
{PORTD=~LED_DATA2[j];delayms(LED_DATA2[1]);}
}
for(i=0;i
{PORTD=~LED_DATA3[j];delayms(LED_DATA3[1]);}
}
for(i=0;i
{PORTD=~LED_DATA4[j];delayms(LED_DATA4[1]);}
}
for(i=0;i
{PORTD=~LED_DATA5[j];delayms(LED_DATA5[1]);}
}
for(i=0;i
{PORTD=~LED_DATA6[j];delayms(LED_DATA6[1]);}
}
for(i=0;i
{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;i
}
/*********************************************/
////////////主程序/////////////////////////
int main (void)
{
Init();
while(1)
{
//keytest();
led_display();//调用LED显示子程序
}
}
PIC16F917LED游侠 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)