《单片机C语言程序设计实训100例——基于8051+Proteus仿真》 第03篇源代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了《单片机C语言程序设计实训100例——基于8051+Proteus仿真》 第03篇源代码相关的知识,希望对你有一定的参考价值。

前面的源代码都有了,就剩下综合设计的没有!
谁有综合设计的源代码发来236259409@qq.com
谢谢

单片机c语言编程100个实例目录1
函数的使用和熟悉
实例3:用单片机控制第一个灯亮
实例4:用单片机控制一个灯闪烁:认识单片机的工作频率
实例5:将 P1口状态分别送入P0、P2、P3口:认识I/O口的引脚功能
实例6:使用P3口流水点亮8位LED
实例7:通过对P3口地址的操作流水点亮8位LED
实例8:用不同数据类型控制灯闪烁时间
实例9:用P0口、P1 口分别显示加法和减法运算结果
实例10:用P0、P1口显示乘法运算结果
实例11:用P1、P0口显示除法运算结果
实例12:用自增运算控制P0口8位LED流水花样
实例13:用P0口显示逻辑"与"运算结果
实例14:用P0口显示条件运算结果
实例15:用P0口显示按位"异或"运算结果
实例16:用P0显示左移运算结果
实例17:"万能逻辑电路"实验
实例18:用右移运算流水点亮P1口8位LED
实例19:用if语句控制P0口8位LED的流水方向
实例20:用swtich语句的控制P0口8位LED的点亮状态
实例21:用for语句控制蜂鸣器鸣笛次数
实例22:用while语句控制LED
实例23:用do-while语句控制P0口8位LED流水点亮
实例24:用字符型数组控制P0口8位LED流水点亮
实例25: 用P0口显示字符串常量
实例26:用P0 口显示指针运算结果
实例27:用指针数组控制P0口8位LED流水点亮
实例28:用数组的指针控制P0 口8 位LED流水点亮
实例29:用P0 、P1口显示整型函数返回值
实例30:用有参函数控制P0口8位LED流水速度
实例31:用数组作函数参数控制流水花样
实例32:用指针作函数参数控制P0口8位LED流水点亮
实例33:用函数型指针控制P1口灯花样
实例34:用指针数组作为函数的参数显示多个字符串
单片机c语言编程100个实例目录2
实例35:字符函数ctype.h应用举例
实例36:内部函数intrins.h应用举例
实例37:标准函数stdlib.h应用举例
实例38:字符串函数string.h应用举例
实例39:宏定义应用举例2
实例40:宏定义应用举例2
实例41:宏定义应用举例3
* 中断、定时器中断、定时器 *中断、定时器*中断、定时器 /
实例42:用定时器T0查询方式P2口8位控制LED闪烁
实例43:用定时器T1查询方式控制单片机发出1KHz音频
实例44:将计数器T0计数的结果送P1口8位LED显示
实例45:用定时器T0的中断控制1位LED闪烁
实例46:用定时器T0的中断实现长时间定时
实例47:用定时器T1中断控制两个LED以不同周期闪烁
实例48:用计数器T1的中断控制蜂鸣器发出1KHz音频
实例49:用定时器T0的中断实现"渴望"主题曲的播放
实例50-1:输出50个矩形脉冲
实例50-2:计数器T0统计外部脉冲数
实例51-2:定时器T0的模式2测量正脉冲宽度
实例52:用定时器T0控制输出高低宽度不同的矩形波
实例53:用外中断0的中断方式进行数据采集
实例54-1:输出负脉宽为200微秒的方波
实例54-2:测量负脉冲宽度
实例55:方式0控制流水灯循环点亮
实例56-1:数据发送程序
实例56-2:数据接收程序
实例57-1:数据发送程序
实例57-2:数据接收程序
实例58:单片机向PC发送数据
实例59:单片机接收PC发出的数据
*数码管显示*数码管显示 数码管显示数码管显示*/
实例60:用LED数码显示数字5
实例61:用LED数码显示器循环显示数字0~9
实例62:用数码管慢速动态扫描显示数字"1234"
实例63:用LED数码显示器伪静态显示数字1234
实例64:用数码管显示动态检测结果
实例65:数码秒表设计
实例66:数码时钟设计
实例67:用LED数码管显示计数器T0的计数值
实例68:静态显示数字“59”
单片机c语言编程100个实例目录3
键盘控制*键盘控制* *键盘控制 *键盘控制 */
实例69:无软件消抖的独立式键盘输入实验
实例70:软件消抖的独立式键盘输入实验
实例71:CPU控制的独立式键盘扫描实验
实例72:定时器中断控制的独立式键盘扫描实验
实例73:独立式键盘控制的4级变速流水灯
实例74:独立式键盘的按键功能扩展:"以一当四"
实例75:独立式键盘调时的数码时钟实验
实例76:独立式键盘控制步进电机实验
实例77:矩阵式键盘按键值的数码管显示实验
//实例78:矩阵式键盘按键音
实例79:简易电子琴
实例80:矩阵式键盘实现的电子密码锁
液晶显示LCD*液晶显示LCD *液晶显示LCD * *液晶显示LCD*液晶显示LCD *液晶显示LCD */
实例81:用LCD显示字符'A'
实例82:用LCD循环右移显示"Welcome to China"
实例83:用LCD显示适时检测结果
实例84:液晶时钟设计
*一些芯片的使用*24c02 DS18B20 X5045 ADC0832 DAC0832 DS1302 红外遥控/
实例85:将数据"0x0f"写入AT24C02再读出送P1口显示
实例86:将按键次数写入AT24C02,再读出并用1602LCD显示
实例87:对I2C总线上挂接多个AT24C02的读写操作
实例88:基于AT24C02的多机通信 读取程序
实例89:基于AT24C02的多机通信 写入程序
实例90:DS18B20温度检测及其液晶显示
实例91:将数据"0xaa"写入X5045再读出送P1口显示
实例92:将流水灯控制码写入X5045并读出送P1口显示
实例93:对SPI总线上挂接多个X5045的读写操作
实例94:基于ADC0832的数字电压表
实例95:用DAC0832产生锯齿波电压
实例96:用P1口显示红外遥控器的按键值
实例97:用红外遥控器控制继电器
实例98:基于DS1302的日历时钟
实例99:单片机数据发送程序
实例100:电机转速表设计
模拟霍尔脉冲

http://www.dzkfw.com.cn/myxin/51c_language.chm 单片机c语言一百例子
参考技术A /-----------------------------------------------------------------
// 名称:射击训练游戏
//-----------------------------------------------------------------
// 说明:程序启动时液晶屏显示游戏封面,然后显示游戏区,默认弹药为20发,
// K1,K2键用于向上或向下移动枪支,跟踪目标,K3用于发射并模拟枪声,
// 在每次发射时,如果击中则加1分,在击中后如果目标物体尚未移动时,
// 程序不重复加分.弹药用完后可按下K4重新开始.
//-----------------------------------------------------------------
#define F_CPU 4000000UL
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
#include "PG160128.h"
#include "PictureDots.h"
#define INT8U unsigned char
#define INT16U unsigned int
//LCD显示相关函数及相关变量

//按键定义

//蜂鸣器

INT8U HCount = 0,LCount = 0; //控制模拟枪声的延时变量
INT8U Score = 0, Bullet_Count = 20; //得分,剩余弹药数
INT8U Target_x = 0, Target_y = 0; //目标物体位置
INT8U Pre_Target_y = 0; //目标物体上次所在纵坐标位置
INT8U gun_y = 20; //枪支纵坐标(其中横坐标固定为16*8)
//-----------------------------------------------------------------
// 显示成绩与剩余弹药数
//-----------------------------------------------------------------
void Show_Score_and_Bullet()



//-----------------------------------------------------------------
// 键盘中断(INT1)
//-----------------------------------------------------------------
ISR (INT1_vect)

//-----------------------------------------------------------------
// 名称: PG12864LCD显示驱动程序(T6963C) (不带字库)
//-----------------------------------------------------------------
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <string.h>
#include <math.h>
#include <string.h>
#include "PG160128.h"
#define INT8U unsigned char
#define INT16U unsigned int
//-----------------------------------------------------------------
// 变更LCD与MCU的连接时,
// 只需要修改以下数据端口,控制端口及控制引脚定义
//-----------------------------------------------------------------
//LCD数据端口

//LCD控制端口

//LCD控制引脚定义(读,写,命令/数据寄存选择)

//-----------------------------------------------------------------
//LCD控制引脚相关操作

//ASCII字模宽度及高度定义

const INT8U LCD_WIDTH = 20; //宽160像素(160/8 = 20个字节)
const INT8U LCD_HEIGHT = 128; //高128像素
//下面的英文,数字,标点符号等字符点阵存放于程序Flash空间中
//使用时要用pgm_read_byte(INT8U*)函数读取,该函数在avr/pgmspace.h中申明
//本例使用的图像点阵也存放于Flash中.
prog_uchar ASC_MSK[96 * 12] =
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,// < 0x20时
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ' '
0x00,0x30,0x78,0x78,0x78,0x30,0x30,0x00,0x30,0x30,0x00,0x00,// '!'
0x00,0x66,0x66,0x66,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '"'
0x00,0x6c,0x6c,0xfe,0x6c,0x6c,0x6c,0xfe,0x6c,0x6c,0x00,0x00,// '#'
0x30,0x30,0x7c,0xc0,0xc0,0x78,0x0c,0x0c,0xf8,0x30,0x30,0x00,// '$'
0x00,0x00,0x00,0xc4,0xcc,0x18,0x30,0x60,0xcc,0x8c,0x00,0x00,// '%'
0x00,0x70,0xd8,0xd8,0x70,0xfa,0xde,0xcc,0xdc,0x76,0x00,0x00,// '&'
0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '''
0x00,0x0c,0x18,0x30,0x60,0x60,0x60,0x30,0x18,0x0c,0x00,0x00,// '('
0x00,0x60,0x30,0x18,0x0c,0x0c,0x0c,0x18,0x30,0x60,0x00,0x00,// ')'
0x00,0x00,0x00,0x66,0x3c,0xff,0x3c,0x66,0x00,0x00,0x00,0x00,// '*'
0x00,0x00,0x00,0x18,0x18,0x7e,0x18,0x18,0x00,0x00,0x00,0x00,// '+'
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0x60,0x00,// ','
0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,// '-'
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0x00,0x00,// '.'
0x00,0x00,0x02,0x06,0x0c,0x18,0x30,0x60,0xc0,0x80,0x00,0x00,// '/'
0x00,0x7c,0xc6,0xce,0xde,0xd6,0xf6,0xe6,0xc6,0x7c,0x00,0x00,// '0'
0x00,0x10,0x30,0xf0,0x30,0x30,0x30,0x30,0x30,0xfc,0x00,0x00,// '1'
0x00,0x78,0xcc,0xcc,0x0c,0x18,0x30,0x60,0xcc,0xfc,0x00,0x00,// '2'
0x00,0x78,0xcc,0x0c,0x0c,0x38,0x0c,0x0c,0xcc,0x78,0x00,0x00,// '3'
0x00,0x0c,0x1c,0x3c,0x6c,0xcc,0xfe,0x0c,0x0c,0x1e,0x00,0x00,// '4'
0x00,0xfc,0xc0,0xc0,0xc0,0xf8,0x0c,0x0c,0xcc,0x78,0x00,0x00,// '5'
0x00,0x38,0x60,0xc0,0xc0,0xf8,0xcc,0xcc,0xcc,0x78,0x00,0x00,// '6'
0x00,0xfe,0xc6,0xc6,0x06,0x0c,0x18,0x30,0x30,0x30,0x00,0x00,// '7'
0x00,0x78,0xcc,0xcc,0xec,0x78,0xdc,0xcc,0xcc,0x78,0x00,0x00,// '8'
0x00,0x78,0xcc,0xcc,0xcc,0x7c,0x18,0x18,0x30,0x70,0x00,0x00,// '9'
0x00,0x00,0x00,0x38,0x38,0x00,0x00,0x38,0x38,0x00,0x00,0x00,// ':'
0x00,0x00,0x00,0x38,0x38,0x00,0x00,0x38,0x38,0x18,0x30,0x00,// ';'
0x00,0x0c,0x18,0x30,0x60,0xc0,0x60,0x30,0x18,0x0c,0x00,0x00,// '<'
0x00,0x00,0x00,0x00,0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,// '='
0x00,0x60,0x30,0x18,0x0c,0x06,0x0c,0x18,0x30,0x60,0x00,0x00,// '>'
0x00,0x78,0xcc,0x0c,0x18,0x30,0x30,0x00,0x30,0x30,0x00,0x00,// '?'
0x00,0x7c,0xc6,0xc6,0xde,0xde,0xde,0xc0,0xc0,0x7c,0x00,0x00,// '@'
0x00,0x30,0x78,0xcc,0xcc,0xcc,0xfc,0xcc,0xcc,0xcc,0x00,0x00,// 'A'
0x00,0xfc,0x66,0x66,0x66,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00,// 'B'
0x00,0x3c,0x66,0xc6,0xc0,0xc0,0xc0,0xc6,0x66,0x3c,0x00,0x00,// 'C'
0x00,0xf8,0x6c,0x66,0x66,0x66,0x66,0x66,0x6c,0xf8,0x00,0x00,// 'D'
0x00,0xfe,0x62,0x60,0x64,0x7c,0x64,0x60,0x62,0xfe,0x00,0x00,// 'E'
0x00,0xfe,0x66,0x62,0x64,0x7c,0x64,0x60,0x60,0xf0,0x00,0x00,// 'F'
0x00,0x3c,0x66,0xc6,0xc0,0xc0,0xce,0xc6,0x66,0x3e,0x00,0x00,// 'G'
0x00,0xcc,0xcc,0xcc,0xcc,0xfc,0xcc,0xcc,0xcc,0xcc,0x00,0x00,// 'H'
0x00,0x78,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x78,0x00,0x00,// 'I'
0x00,0x1e,0x0c,0x0c,0x0c,0x0c,0xcc,0xcc,0xcc,0x78,0x00,0x00,// 'J'
0x00,0xe6,0x66,0x6c,0x6c,0x78,0x6c,0x6c,0x66,0xe6,0x00,0x00,// 'K'
0x00,0xf0,0x60,0x60,0x60,0x60,0x62,0x66,0x66,0xfe,0x00,0x00,// 'L'
0x00,0xc6,0xee,0xfe,0xfe,0xd6,0xc6,0xc6,0xc6,0xc6,0x00,0x00,// 'M'
0x00,0xc6,0xc6,0xe6,0xf6,0xfe,0xde,0xce,0xc6,0xc6,0x00,0x00,// 'N'
0x00,0x38,0x6c,0xc6,0xc6,0xc6,0xc6,0xc6,0x6c,0x38,0x00,0x00,// 'O'
0x00,0xfc,0x66,0x66,0x66,0x7c,0x60,0x60,0x60,0xf0,0x00,0x00,// 'P'
0x00,0x38,0x6c,0xc6,0xc6,0xc6,0xce,0xde,0x7c,0x0c,0x1e,0x00,// 'Q'
0x00,0xfc,0x66,0x66,0x66,0x7c,0x6c,0x66,0x66,0xe6,0x00,0x00,// 'R'
0x00,0x78,0xcc,0xcc,0xc0,0x70,0x18,0xcc,0xcc,0x78,0x00,0x00,// 'S'
0x00,0xfc,0xb4,0x30,0x30,0x30,0x30,0x30,0x30,0x78,0x00,0x00,// 'T'
0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x78,0x00,0x00,// 'U'
0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x78,0x30,0x00,0x00,// 'V'
0x00,0xc6,0xc6,0xc6,0xc6,0xd6,0xd6,0x6c,0x6c,0x6c,0x00,0x00,// 'W'
0x00,0xcc,0xcc,0xcc,0x78,0x30,0x78,0xcc,0xcc,0xcc,0x00,0x00,// 'X'
0x00,0xcc,0xcc,0xcc,0xcc,0x78,0x30,0x30,0x30,0x78,0x00,0x00,// 'Y'
0x00,0xfe,0xce,0x98,0x18,0x30,0x60,0x62,0xc6,0xfe,0x00,0x00,// 'Z'
0x00,0x3c,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3c,0x00,0x00,// '['
0x00,0x00,0x80,0xc0,0x60,0x30,0x18,0x0c,0x06,0x02,0x00,0x00,// '\'
0x00,0x3c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x3c,0x00,0x00,// ']'
0x10,0x38,0x6c,0xc6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '^'
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,// '_'
0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '`'
0x00,0x00,0x00,0x00,0x78,0x0c,0x7c,0xcc,0xcc,0x76,0x00,0x00,// 'a'
0x00,0xe0,0x60,0x60,0x7c,0x66,0x66,0x66,0x66,0xdc,0x00,0x00,// 'b'
0x00,0x00,0x00,0x00,0x78,0xcc,0xc0,0xc0,0xcc,0x78,0x00,0x00,// 'c'
0x00,0x1c,0x0c,0x0c,0x7c,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,// 'd'
0x00,0x00,0x00,0x00,0x78,0xcc,0xfc,0xc0,0xcc,0x78,0x00,0x00,// 'e'
0x00,0x38,0x6c,0x60,0x60,0xf8,0x60,0x60,0x60,0xf0,0x00,0x00,// 'f'
0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0x7c,0x0c,0xcc,0x78,// 'g'
0x00,0xe0,0x60,0x60,0x6c,0x76,0x66,0x66,0x66,0xe6,0x00,0x00,// 'h'
0x00,0x18,0x18,0x00,0x78,0x18,0x18,0x18,0x18,0x7e,0x00,0x00,// 'i'
0x00,0x0c,0x0c,0x00,0x3c,0x0c,0x0c,0x0c,0x0c,0xcc,0xcc,0x78,// 'j'
0x00,0xe0,0x60,0x60,0x66,0x6c,0x78,0x6c,0x66,0xe6,0x00,0x00,// 'k'
0x00,0x78,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7e,0x00,0x00,// 'l'
0x00,0x00,0x00,0x00,0xfc,0xd6,0xd6,0xd6,0xd6,0xc6,0x00,0x00,// 'm'
0x00,0x00,0x00,0x00,0xf8,0xcc,0xcc,0xcc,0xcc,0xcc,0x00,0x00,// 'n'
0x00,0x00,0x00,0x00,0x78,0xcc,0xcc,0xcc,0xcc,0x78,0x00,0x00,// 'o'
0x00,0x00,0x00,0x00,0xdc,0x66,0x66,0x66,0x66,0x7c,0x60,0xf0,// 'p'
0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0x7c,0x0c,0x1e,// 'q'
0x00,0x00,0x00,0x00,0xec,0x6e,0x76,0x60,0x60,0xf0,0x00,0x00,// 'r'
0x00,0x00,0x00,0x00,0x78,0xcc,0x60,0x18,0xcc,0x78,0x00,0x00,// 's'
0x00,0x00,0x20,0x60,0xfc,0x60,0x60,0x60,0x6c,0x38,0x00,0x00,// 't'
0x00,0x00,0x00,0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,// 'u'
0x00,0x00,0x00,0x00,0xcc,0xcc,0xcc,0xcc,0x78,0x30,0x00,0x00,// 'v'
0x00,0x00,0x00,0x00,0xc6,0xc6,0xd6,0xd6,0x6c,0x6c,0x00,0x00,// 'w'
0x00,0x00,0x00,0x00,0xc6,0x6c,0x38,0x38,0x6c,0xc6,0x00,0x00,// 'x'
0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x3c,0x0c,0x18,0xf0,// 'y'
0x00,0x00,0x00,0x00,0xfc,0x8c,0x18,0x60,0xc4,0xfc,0x00,0x00,// 'z'
0x00,0x1c,0x30,0x30,0x60,0xc0,0x60,0x30,0x30,0x1c,0x00,0x00,// ''
0x00,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x00,0x00,// '|'
0x00,0xe0,0x30,0x30,0x18,0x0c,0x18,0x30,0x30,0xe0,0x00,0x00,// ''
0x00,0x73,0xda,0xce,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '~'
;
struct typFNT_GB16 //汉字字模数据结构

INT8U Index[2]; //汉字内码,2字节
INT8U Msk[24]; //汉字点阵
;
//本例汉字点阵库
const struct typFNT_GB16 GB_16[] = //12*12点阵,宋体小五号,用Zimo软件取得点阵
"得",0x27,0xC0,0x24,0x40,0x57,0xC0,0x94,0x40,0x27,0xC0,0x60,0x00,
0xAF,0xE0,0x20,0x80,0x2F,0xE0,0x24,0x80,0x21,0x80,0x00,0x00,
"分",0x11,0x00,0x11,0x00,0x20,0x80,0x20,0x80,0x40,0x40,0xBF,0xA0,
0x08,0x80,0x08,0x80,0x10,0x80,0x20,0x80,0xC7,0x00,0x00,0x00,
":",0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
"★",0x04,0x00,0x04,0x00,0x0E,0x00,0x0E,0x00,0xFF,0xE0,0x7F,0xC0,
0x1F,0x00,0x1F,0x00,0x3B,0x80,0x20,0x80,0x40,0x40,0x00,0x00,
"■",0x00,0x00,0x7F,0xC0,0x7F,0xC0,0x7F,0xC0,0x7F,0xC0,0x7F,0xC0,
0x7F,0xC0,0x7F,0xC0,0x7F,0xC0,0x7F,0xC0,0x00,0x00,0x00,0x00,

;
INT8U gCurRow,gCurCol; //当前行,列
//-----------------------------------------------------------------
// LCD控制相关函数
//-----------------------------------------------------------------
INT8U Status_BIT_01(); //状态位STA1,STA0判断(读写指令和读写数据)
INT8U Status_BIT_3(); //状态位ST3判断(数据自动写状态)
INT8U LCD_Write_Command(INT8U cmd); //写无参数的指令
INT8U LCD_Write_Command_P1(INT8U cmd,INT8U para1); //写单参数的指令
INT8U LCD_Write_Command_P2(INT8U cmd,INT8U para1,INT8U para2); //写双参数的指令
INT8U LCD_Write_Data(INT8U dat); //写数据
INT8U LCD_Read_Data(); //读数据
void Clear_Screen(); //清屏
char LCD_Initialise(); //LCD初始化
void Set_LCD_POS(INT8U row, INT8U col); //设置当前地址
void OutToLCD(INT8U Dat,INT8U x,INT8U y); //显示辅助函数
void Line(INT8U x1, INT8U y1, INT8U x2, INT8U y2, INT8U Mode); //绘制直线
void Pixel(INT8U x,INT8U y, INT8U Mode); //绘点
//-----------------------------------------------------------------
// 读状态
//-----------------------------------------------------------------
INT8U Read_LCD_Status()



//-----------------------------------------------------------------
// 读数据
//-----------------------------------------------------------------
INT8U Read_LCD_Data()



//-----------------------------------------------------------------
// 写数据
//-----------------------------------------------------------------
void Write_Data(INT8U dat)



//-----------------------------------------------------------------
// 写命令
//-----------------------------------------------------------------
void Write_Command(INT8U cmd)



//-----------------------------------------------------------------
// 状态位STA1,STA0判断(读写指令和读写数据)
//-----------------------------------------------------------------
INT8U Status_BIT_01()



//-----------------------------------------------------------------
// 状态位ST3判断(数据自动写状态)
//-----------------------------------------------------------------
INT8U Status_BIT_3()



//-----------------------------------------------------------------
// 写双参数的指令
//-----------------------------------------------------------------
INT8U LCD_Write_Command_P2(INT8U cmd,INT8U para1,INT8U para2)



//-----------------------------------------------------------------
// 写单参数的指令
//-----------------------------------------------------------------
INT8U LCD_Write_Command_P1(INT8U cmd,INT8U para1)



//-----------------------------------------------------------------
// 写无参数的指令
//-----------------------------------------------------------------
INT8U LCD_Write_Command(INT8U cmd)



//-----------------------------------------------------------------
// 写数据
//-----------------------------------------------------------------
INT8U LCD_Write_Data(INT8U dat)



//-----------------------------------------------------------------
// 读数据
//-----------------------------------------------------------------
INT8U LCD_Read_Data()



//-----------------------------------------------------------------
// 设置当前地址
//-----------------------------------------------------------------
void Set_LCD_POS(INT8U row, INT8U col)



//-----------------------------------------------------------------
// 清屏
//-----------------------------------------------------------------
void Clear_Screen()



//-----------------------------------------------------------------
// LCM 初始化
//-----------------------------------------------------------------
char LCD_Initialise()



//-----------------------------------------------------------------
// ASCII及汉字显示(wb表示是否反白显示)
//-----------------------------------------------------------------
void Display_Str_at_xy(INT8U x,INT8U y,char* Buffer,INT8U wb)



//-----------------------------------------------------------------
// 输出起点x不是8的倍数时,原字节分成两部分输出到LCD
//-----------------------------------------------------------------
void OutToLCD(INT8U Dat,INT8U x,INT8U y)



//-----------------------------------------------------------------
// 绘点函数
// 参数:点的坐标,模式1/0分别为显示与清除点
//-----------------------------------------------------------------
void Pixel(INT8U x,INT8U y, INT8U Mode)



//-----------------------------------------------------------------
// 两数交换
//-----------------------------------------------------------------
void Exchange(INT8U *a, INT8U *b)



//-----------------------------------------------------------------
// 绘制直线函数
// 参数:起点与终点坐标,模式为显示(1)或清除(0),点阵不超过255*255)
//-----------------------------------------------------------------
void Line(INT8U x1,INT8U y1, INT8U x2,INT8U y2, INT8U Mode)



//-----------------------------------------------------------------
// 绘制图像(图像数据来自于Flash程序ROM空间)
//-----------------------------------------------------------------
void Draw_Image(prog_uchar *G_Buffer, INT8U Start_Row, INT8U Start_Col)



/ 名称: PG12864LCD显示驱动程序头文件
//-----------------------------------------------------------------
#include <stdio.h>
#include <math.h>
#include <string.h>
#define STX 0x02
#define ETX 0x03
#define EOT 0x04
#define ENQ 0x05
#define BS 0x08
#define CR 0x0D
#define LF 0x0A
#define DLE 0x10
#define ETB 0x17
#define SPACE 0x20
#define COMMA 0x2C
#define TRUE 1
#define FALSE 0
#define HIGH 1
#define LOW 0
//T6963C 命令定义
#define LC_CUR_POS 0x21 //光标位置设置
#define LC_CGR_POS 0x22 //CGRAM偏置地址设置
#define LC_ADD_POS 0x24 //地址指针位置
#define LC_TXT_STP 0x40 //文本区首址
#define LC_TXT_WID 0x41 //文本区宽度
#define LC_GRH_STP 0x42 //图形区首址
#define LC_GRH_WID 0x43 //图形区宽度
#define LC_MOD_OR 0x80 //显示方式:逻辑或
#define LC_MOD_XOR 0x81 //显示方式:逻辑异或
#define LC_MOD_AND 0x82 //显示方式:逻辑与
#define LC_MOD_TCH 0x83 //显示方式:文本特征
#define LC_DIS_SW 0x90 //显示开关:
//D0=1/0:光标闪烁启用/禁用;
//D1=1/0:光标显示启用/禁用;
//D2=1/0:文本显示启用/禁用;
//D3=1/0:图形显示启用/禁用;
#define LC_CUR_SHP 0xA0 //光标形状选择:0xA0-0xA7表示光标占的行数
#define LC_AUT_WR 0xB0 //自动写设置
#define LC_AUT_RD 0xB1 //自动读设置
#define LC_AUT_OVR 0xB2 //自动读/写结束
#define LC_INC_WR 0xC0 //数据写,地址加1
#define LC_INC_RD 0xC1 //数据读,地址加1
#define LC_DEC_WR 0xC2 //数据写,地址减1
#define LC_DEC_RD 0xC3 //数据读,地址减1
#define LC_NOC_WR 0xC4 //数据写,地址不变
#define LC_NOC_RD 0xC5 //数据读,地址不变
#define LC_SCN_RD 0xE0 //读屏屏
#define LC_SCN_CP 0xE8 //屏幕拷贝
#define LC_BIT_OP 0xF0 //位操作:D0-D2:定义D0-D7位;D3:1置位;0:清除
/ 游戏封面数据存放于Flash程序空间
//-----------------------------------------------------------------
prog_uchar Game_Surface[] = 160,110, //游戏封面:160x110

;
//-----------------------------------------------------------------
// 枪支图像数据存放于Flash程序空间
//-----------------------------------------------------------------
prog_uchar Gun_Image[] = 24,12, //枪支图像,W/H:24*12
0x03,0x00,0x00,0x07,0x80,0x00,0x07,0x80,0x00,0x7F,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFC,0x7F,0xFF,0xFC,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x00,0x7F,0x00,0x00,
0x7F,0x00,0x00,0x1F
;

参考资料:片机C语言程序设计实训100例——基于8051+Proteus仿真 压缩包

参考技术B 我也可以要一份嘛 参考技术C 可以的本回答被提问者采纳

以上是关于《单片机C语言程序设计实训100例——基于8051+Proteus仿真》 第03篇源代码的主要内容,如果未能解决你的问题,请参考以下文章

请教,C8051F340单片机读P4口的方法(c语言)。我的方法是与立即数,但这样貌似有不读数不稳定的时候。

怎样在单片机C语言里面产生一个0到100的随机数

单片机RGB调色程序 要求基于PWM(STC系列单片机c语言)可以实现至少60种颜色调节,有多种模

基于8051单片机实现电子时钟+数字秒表设计

资料分享基于8051单片机与1601LCD的计算器设计(仿真 程序 论文)基于51单片机数字电压表的设计(仿真程序原理图论文)

51单片机c语言