📄 main.c
字号:
/* led模块例程
HCS908_QG8 单片机开发板
实验介绍:
本程序是显示模块的例程,所接器件为四位八段led数码管,其中PTB0-PTB3
与数码管的位选相连接,PTB4,PTB5与74LS164连接确定你开发板上拨码开
关JP1(图片上的12)的两位和JP4(图片上的9)的5、6、7、8位处于on),
而其他位处于远离on!
实验现象:
四位数码管显示4321
author:QGL
any question mail me:
libing.qu@free-tech.com.cn
*/
/*****************头文件*****************************************/
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
/*******************定义变量和函数********************************/
unsigned char tab[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xff,0xf6};//0-9,-,全灭
void sendbyte(unsigned char byte);
void delay_50ms(unsigned int t);
void display(uint i);
/*****************主函数*****************************************/
void main(void){
PTBDD=0x3f; //PTB5--PTB0设置为输出
EnableInterrupts; /* enable interrupts */
/* include your code here */
for(;;){
__RESET_WATCHDOG();
PTBD_PTBD0=0;
PTBD_PTBD1=0;
PTBD_PTBD2=1;//选中第一位
PTBD_PTBD3=0;
sendbyte(4); //发送数字4的段码
delay_50ms(1);
PTBD_PTBD0=0;
PTBD_PTBD1=0;
PTBD_PTBD2=0;
PTBD_PTBD3=1;//选中第二位
sendbyte(3); //发送数字3的段码
delay_50ms(1);
PTBD_PTBD0=1;//选中第三位
PTBD_PTBD1=0;
PTBD_PTBD2=0;
PTBD_PTBD3=0;
sendbyte(2); //发送数字2的段码
delay_50ms(1);
PTBD_PTBD0=0;
PTBD_PTBD1=1;//选中第四位
PTBD_PTBD2=0;
PTBD_PTBD3=0;
sendbyte(1); //发送数字1的段码
delay_50ms(1);
}
}
/*****************模拟串口发送段码函数*****************************************/
void sendbyte(uchar byte){
unsigned char num,c;
num=tab[byte];//0xfc;
for(c=0;c<8;c++){
PTBD_PTBD4=1;
PTBD_PTBD4=0; //模拟串口时钟
if(num&0x01)
PTBD_PTBD5=1;
else
PTBD_PTBD5=0;
PTBD_PTBD4=1;
num>>=1;
}
}
/*****************延时函数*****************************************/
void delay_50ms(unsigned int t){
unsigned int j;
unsigned int i;
for(i=t;i>0;i--){
for(j=255;j>0;j--)
{;}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -