中山学院单片机综合实验报告-键盘、数码管与点阵管实验

电子科技大学中山学院学生实验报告

院别:电子信息学院 课程名称:单片机综合实验 实验名称 成绩 实验时间 批改时间 键盘、数码管与点阵管实验 报 告 内 容 一、实验目的和任务 1、掌握80C51单片机矩阵键盘的构成原理和软件编程。 2、掌握80C51单片机数码管动态显示原理和编程。 3、掌握80C51单片机LED点阵的构成原理和软件编程。 二、实验原理简介 ZSC-1实验箱为MCU1配置了2*8矩阵键盘、8位LED数码管、8*8LED点阵管等人机对话设备,相关电路如下图所示。为提高口线利用率,单片机P0口分时用作矩阵键盘的行扫描口、数码管的段码口以及点阵管的列驱动口,P2.2、P2.1、P2.0与74HC138译码器及2片74HC240反相驱动器相配合,用作数码管的位码口和点阵管的行驱动口。 P3.4、P3.5用于读取矩阵键盘的列状态,P2.3、P4.4的作用为:P2.3=1时,数码管和点阵管均关闭显示,P2.3=0而P4.4=1或0时,数码管或点阵管开通显示。 VccK0K1K2K3K4K5K6P35P34K7P00P01P02P03P04P05P06P07K8K9K*K#KF1KF2KF3KF4CS12024681113151711974HC240VCC1A01A11A21A32A02A12A22A31OE2OE1Y01Y11Y21Y32Y02Y12Y22Y3GND18161412975310VccVcc74HC138VCCE3E1E2A2A1A0GNDY0Y1Y2Y3Y4Y5Y6Y715141312111097CS110K8550CS22024681113151711916645321874HC240VCC1A01A11A21A32A02A12A22A31OE2OE1Y01Y11Y21Y32Y02Y12Y22Y3GND181614129753109148121725R1R2R3R4R5R6R7R88x8点阵管121298698P2.3P2.2P2.1P2.024232221com1com2com3com4com1com2com3com4VccP4.4P0.7P0.6P0.5P0.4P0.3P0.2P0.1P0.0293233343536373839CS210KC1C2C3C4C5C6C7C8dpgfedcbadpgfedcba13341061115163510124711470Ωx835101247116MCU1STC12C5A60S2共阳极数码管 1

三、实验内容和步骤 1、在8个数码上顺序显示0-7八个数字。程序代码如下所示: #include unsigned lettern[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void delay(int n) { int i; int j; for(i=0; i=0; j--); } void display(unsigned char *dis,unsigned char n) { unsigned char i,x; for (i=0;i sfr P4 = 0xC0; sfr P4SW = 0xBB; sbit P44=P4^4; unsigned char code led88n[16][8]= { {0x00,0x18,0x24,0x24,0x24,0x24,0x18,0x00}, //'0' {0x00,0x08,0x18,0x08,0x08,0x08,0x1C,0x00}, //'1' {0x00,0x18,0x24,0x04,0x08,0x10,0x3C,0x00}, //'2' {0x00,0x3C,0x08,0x10,0x08,0x04,0x24,0x18}, //'3' {0x00,0x08,0x18,0x28,0x28,0x3C,0x08,0x08}, //'4' 2

{0x00,0x3C,0x20,0x38,0x04,0x24,0x18,0x00}, //'5' {0x00,0x18,0x20,0x38,0x24,0x24,0x18,0x00}, //'6' {0x00,0x3C,0x04,0x08,0x10,0x10,0x10,0x00}, //'7' {0x00,0x18,0x24,0x24,0x18,0x24,0x24,0x18}, //'8' {0x00,0x18,0x24,0x24,0x1C,0x04,0x24,0x18}, //'9' {0x0C,0x12,0x12,0x12,0x1E,0x12,0x12,0x00}, //'A' {0x0E,0x09,0x09,0x0E,0x09,0x09,0x09,0x0E}, //'B' {0x00,0x1C,0x20,0x20,0x20,0x20,0x1C,0x00}, //'C' {0x0E,0x1C,0x12,0x12,0x12,0x12,0x1C,0x00}, //'D' {0x00,0x1E,0x10,0x1E,0x10,0x10,0x1E,0x00}, //'E' {0x00,0x1E,0x10,0x10,0x1E,0x10,0x10,0x00}, //'F' }; void delay(int n) { int i; int j; for(i=0; i=0; j--); } void display88(unsigned char *chs) //显示8*8LED点阵 { unsigned char i; P44=0; for(i=0;i<8;i++) { P0=~chs[i]; //每行值 P2=i; //第几行 delay( 1 ); P2=0xff; } P44=1; } void main(void) { unsigned char dis[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; char i; unsigned int j; P4SW|=0x10; //将P44设为IO while(1) { for(i=0;i<16;i++) for(j=0;j<100;j++) display88(led88n[dis[i]]); } } 3

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4