PIC单片机及FPGA实验系统设计 第18页
temp=PORTD & 0xf0;
if (temp!=0xf0){
x=temp;
TRISD=0x0f;
PORTD=0x0f;
temp=PORTD & 0x0f;
y=temp;
z=x|y;
switch(z){
case 0xee:k=0;break;
case 0xed:k=1;break;
case 0xeb:k=2;break;
case 0xe7:k=3;break;
case 0xde:k=4;break;
case 0xdd:k=5;break;
case 0xdb:k=6;break;
case 0xd7:k=7;break;
case 0xbe:k=8;break;
case 0xbd:k=9;break;
case 0xbb:k=10;break;
case 0xb7:k=11;break;
case 0x7e:k=12;break;
case 0x7d:k=13;break;
case 0x7b:k=14;break;
case 0x77:k=15;break;
}
}
}
}
void main(void){
TRISC=0x00;
while(1){
keyscan();
PORTC=a[k];
}
}
附录(辣):数码管实验:动态显示:文件dongtaixianshi.C
//动态显示
#include<pic.h>
Unsigned char segcode[16]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}; //显示内容
void delay(unsigned char n){ //延时程序
unsigned char i;
unsigned char j;
while(n>0){
for(i=0;i<20;i++){
for(j=0;j<50;j++){
}
}
n--;
}
}
void display(unsigned int date){ //动态显示,按位显示,先把位拆开,然后按位显示
TRISA=0x00;
TRISD=0x00;
PORTA=0X7F;
PORTD=segcode[date%1000];
delay(8);
PORTD=0X00;
PORTA=0XBF;
PORTD=segcode[date%1000/100];
delay(8);
PORTD=0X00;
PORTA=0XE0;
PORTD=segcode[date%100/10];
delay(8);
PORTD=0X00;
PORTA=0X7F;
PORTD=segcode[date%10];
delay(8);
PORTD=0X00;
}
void main(void){
unsigned int date=1234;
while(1){
display(date);
}
}
附录(七):模拟显示:shumaguan-1.c
//实现功能:开机时显示0,第一次按下时,显示D1,
//第二次按下时,显示D1D2,。。5个全显示完,再按下键时候,给出提示声音
#include<pic.h>
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char dispbuf[8]={0,16,16,16,16,16,16,16};
unsigned char dispbitcount; //动态显示位记录
unsigned char key; //key记录
unsigned char keypos; //输入次数记录
bit alarmflag;
//子函数声明
void T0_initial(void); //T0初始化
void change(unsigned char *p,unsigned char count); //转换
void key_chuli(void); //KEY处理
void keyskan(void); //键盘扫描
void delay(unsigned char); //可调延时间程序
void display(void); //动态显示子程序
void main(void){ //主程序
T0_initial();
while(1){
keyskan();
key_chuli();
}
}
void change(unsigned char *p,unsigned char count){
while(count>0){
*(p+count)=*(p+count-1);
count--;
}
}
void T0_Intial(void){ //中断产生16ms延时
OPTION=0x05; //设定分频比为1:64
T0IF=0;
T0IE=1;
GIE=1;
}
void keycan(void){
unsigned char temp,x,y,z;
TRISD=0xf0;
PORTD=0xf0;
temp=PORTD & 0xf0;
if (temp!=0xf0){
delay(8);
temp=PORTD & 0xf0;
if (temp!=0xf0){
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] ... 下一页 >>
PIC单片机及FPGA实验系统设计 第18页下载如图片无法显示或论文不完整,请联系qq752018766