单纯数码管的显示C程序-用PIC16F877A单片机
扫描二维码
随时随地手机看文章
单纯数码管的显示C程序
#include
#define HC595_SER RB7
#define HC595_SCK RB6
#define HC595_RCK RB5
#define key_164_data RB3
#define key_164_clk RB2
#define key_com1 RB1
#define key_com0 RB0
#define TURE 1
bit key_finish; //定义位变量,这是PICmate仿真软件环境的特有的地方 unsigned int sample_key;
unsigned int sample_keyBuf[2];
unsigned int key_value;
unsigned char key_row_sel;
unsigned char key_number;//键号
unsigned int T100ms;
unsigned char disbuf[8];
const unsigned char seven_seg[16]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//----------------------------------------------
void disbuf_update(void)
{
//if(key_number>=16)
//{
//disbuf[0]=0xff;
//disbuf[1]=0xff;
//disbuf[2]=0xff;
//disbuf[3]=0xff;
//disbuf[4]=0xff;
//disbuf[5]=0xff;
//disbuf[6]=0xff;
//disbuf[7]=0xff;
//return;
//}
disbuf[0]=seven_seg[1];
disbuf[1]=seven_seg[2];
disbuf[2]=seven_seg[3];
disbuf[3]=seven_seg[4];
disbuf[4]=seven_seg[5];
disbuf[5]=seven_seg[6];
disbuf[6]=seven_seg[7];
disbuf[7]=seven_seg[8];
}
//----------------------------------------------
//发送一个字节
void s_pData(unsigned char key) //形参key对应着实参disbuf[i]
{
unsigned char i;
for(i=0;i<8;i++)
{
if(0x80&(key< HC595_SER=1;
else HC595_SER=0;
HC595_SCK=0;
HC595_SCK=1;
}
}
//----------------------------------------------
void display (void)
{
unsigned char i;
for(i=0;i<8;i++)
s_pData(disbuf[i]);
HC595_RCK=0;
HC595_RCK=1;
}
//----------------------------------------------
//主程序
int main(void)
{
PORTB=0;
TRISB=0x03;
disbuf_update();
display();
}
//----------------------------------------------
它的电路图可以参考用PIC16F877A单片机驱动按键控制8个数码管的显示电路图.