PIC单片机及FPGA实验系统设计 第19页
keypos++;
x=temp;
TRISD=0x0f;
PORTD=0xf0;
temp=PORTD & 0x0f;
y=temp;
z=x|y;
switch(z){
case 0xe1:k=0;break;
case 0xe2:k=1;break;
case 0xe4:k=2;break;
case 0xe8:k=3;break;
case 0xd1:k=4;break;
case 0xd2:k=5;break;
case 0xd4:k=6;break;
case 0xd8:k=7;break;
case 0xb1:k=8;break;
case 0xb2:k=9;break;
case 0xb4:k=10;break;
case 0xb8:k=11;break;
case 0x71:k=12;break;
case 0x72:k=13;break;
case 0x74:k=14;break;
case 0x78:k=15;break;
}
}
}
}
void delay(unsigned char z){
unsigned char i,j;
while(z>0){
for(i=0;i<20;i++){
for(j=0;j<50;j++){
}
}
z--;
}
}
void key_chuli(void){
if(keypos<8){
change(dispbuf,keypos);
dispbuf[0]=key;
}
else{
keypos=8;
alarmflag=1;
}
}
//中断服务程序
void interrupt T0(void){
if(T0IF==1){
T0IE=0;
display();
T0IF=0;
T0IE=1;
}
}
void dislay(void){
TRISD=0x00;
TRISC=0x00;
TRISE0=1;
PORTC=dispbitcode[dispbitcount];
PORTD=dispcode[dispbuf[dispbitcount]];
dispbitcout++;
if(dispbitcount==8){
dispbitcount=0;
}
if (larmflag=1){
PORTE1=~PORTE1;
}
}
附录(八):柱子的移动,文件为matrix_zhu.c
#include<pic.h>
unsigned char taba[]={0xfe,0xfd,0xfb,0xf7,0xef,0xbf,0xdf,0x7f};
unsigned char tabb[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//扫描码
void delay(void);
void main(void){
TRISC=0x00;
TRISD=0x00;
unsigned char i,j;
while(1){
for(j=0;j<3;j++){ //柱子从右到左三次
for(i=0;i<8;i++){
PORTD=taba[i];
PORTC=0xff;
delay();
}
}
for(j=0;j<3;j++){ //柱子从左向右三次
for(i=0;i<8;i++){
PORTD=taba[7-i];
PORTC=0xff;
delay();
}
}
for(j=0;j<3;j++){ //柱子从顶向底三次
for(i=0;i<8;i++){
PORTC=tabb[i];
PORTD=0x00;
delay();
}
}
for(j=0;j<3;j++){ //柱子从底向顶三次
for(i=0;i<8;i++){
PORTC=tabb[7-i];
PORTD=0x00;
delay();
}
}
}
void delay(){
unsigned char i,j;
for(i=0;i<100;i++){
for(j=0;j<100;j++){
}
}
}
附录(九):LED点阵显示数字实验:matrix_num.C
//用LED点阵显示0—9
#include<pic.h>
unsigned char tab[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code colcode[10][8]={{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0
{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] ... 下一页 >>
PIC单片机及FPGA实验系统设计 第19页下载如图片无法显示或论文不完整,请联系qq752018766