本帖最后由 呼呼呼气 于 2020-11-15 13:07 编辑
这是我基于STM32做出的超声波测距,显示屏是LCD12864
main.c
#include "stm32f10x.h"
#include "led.h"
#include "SysTick.h"
//#include "ultrasonic.h"
#include "usart.h"
#include <stdio.h>
#include "chaoshengbo.h"
#include "lcd.h"
#include "lcd_function.h"
//void key_menu_1(void);
volatile u32 count,Distance0,Distance1;
uint8_t aa[10];//打印AD值的一个字符串数组
char length;
int main(void)
{
write_com(0x01);
delay_us(100);
hcsr04_NVIC();
Hcsr04Init();
USART1_Init();
LCD12864Configuration();
// printf("串口初始化成功!\n");
//
// Hcsr04Init();
// printf("超声波初始化成功!\n");//测试程序是否卡在下面两句上面
//
Hcsr04GetLength();
// printf("距离为:%.3f\n",length);
while ( 1 )
{
length = Hcsr04GetLength(); //计算出实际电压值
sprintf((char*)aa,"%.2d ",length); //sprintf的作用是将一个格式化的字符串输出到一个目的字符串中,而printf是将一个格式化的字符串输出到屏幕
chaoshenbo_LCDdisplay(); //显示一些基本信息
display_str(3,4,aa); //显示sprintf函数的aa字符串数组
Delay_Ms(100);
}
}
//void key_menu_1(void)
//{
// length = Hcsr04GetLength(); //计算出实际电压值
// sprintf((char*)aa,"%.2d ",length); //sprintf的作用是将一个格式化的字符串输出到一个目的字符串中,而printf是将一个格式化的字符串输出到屏幕
// chaoshenbo_LCDdisplay(); //显示一些基本信息
// display_str(3,4,aa); //显示sprintf函数的aa字符串数组
// Delay_Ms(100);
//}
#include "chaoshengbo.h"
u16 msHcCount = 0;//ms计数
void Hcsr04Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //生成用于定时器设置的结构体
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(HCSR04_CLK, ENABLE);
//IO初始化
GPIO_InitStructure.GPIO_Pin =HCSR04_TRIG; //发送电平引脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(HCSR04_PORT, &GPIO_InitStructure);
GPIO_ResetBits(HCSR04_PORT,HCSR04_TRIG);
GPIO_InitStructure.GPIO_Pin = HCSR04_ECHO; //返回电平引脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
GPIO_Init(HCSR04_PORT, &GPIO_InitStructure);
GPIO_ResetBits(HCSR04_PORT,HCSR04_ECHO);
//定时器初始化 使用基本定时器TIM6
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); //使能对应RCC时钟
//配置定时器基础结构体
TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Period = (1000-1); //设置在下一个更新事件装入活动的自动重装载寄存器周期的值 计数到1000为1ms
TIM_TimeBaseStructure.TIM_Prescaler =(72-1); //设置用来作为TIMx时钟频率除数的预分频值 1M的计数频率 1US计数
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;//不分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位
TIM_ClearFlag(TIM6, TIM_FLAG_Update); //清除更新中断,免得一打开中断立即产生中断
TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE); //打开定时器更新中断
hcsr04_NVIC();
TIM_Cmd(TIM6,DISABLE);
}
//tips:static函数的作用域仅限于定义它的源文件内,所以不需要在头文件里声明
static void OpenTimerForHc() //打开定时器
{
TIM_SetCounter(TIM6,0);//清除计数
msHcCount = 0;
TIM_Cmd(TIM6, ENABLE); //使能TIMx外设
}
static void CloseTimerForHc() //关闭定时器
{
TIM_Cmd(TIM6, DISABLE); //使能TIMx外设
}
//NVIC配置
void hcsr04_NVIC(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn; //选择串口1中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占式中断优先级设置为1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应式中断优先级设置为1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能中断
NVIC_Init(&NVIC_InitStructure);
}
//定时器6中断服务程序
void TIM6_IRQHandler(void) //TIM3中断
{
if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) //检查TIM3更新中断发生与否
{
TIM_ClearITPendingBit(TIM6, TIM_IT_Update ); //清除TIMx更新中断标志
msHcCount++;
}
}
//获取定时器时间
u32 GetEchoTimer(void)
{
u32 t = 0;
t = msHcCount*1000;//得到MS
t += TIM_GetCounter(TIM6);//得到US
TIM6->CNT = 0; //将TIM2计数寄存器的计数值清零
Delay_Ms(50);
return t;
}
chaoshengbo.c
//一次获取超声波测距数据 两次测距之间需要相隔一段时间,隔断回响信号
//为了消除余震的影响,取五次数据的平均值进行加权滤波。
float Hcsr04GetLength(void)
{
u32 t = 0;
int i = 0;
float lengthTemp = 0;
float sum = 0;
while(i!=5)
{
TRIG_Send = 1; //发送口高电平输出
Delay_Us(20);
TRIG_Send = 0;
while(ECHO_Reci == 0); //等待接收口高电平输出
OpenTimerForHc(); //打开定时器
i = i + 1;
while(ECHO_Reci == 1);
CloseTimerForHc(); //关闭定时器
t = GetEchoTimer(); //获取时间,分辨率为1US
lengthTemp = ((float)t/58.0);//cm
sum = lengthTemp + sum ;
}
lengthTemp = sum/5.0;
return lengthTemp;
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** 函数名称: Delay_Ms_Ms
** 功能描述: 延时1MS (可通过仿真来判断他的准确度)
** 参数描述:time (ms) 注意time<65535
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void Delay_Ms(uint16_t time) //延时函数
{
uint16_t i,j;
for(i=0;i<time;i++)
for(j=0;j<10260;j++);
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** 函数名称: Delay_Ms_Us
** 功能描述: 延时1us (可通过仿真来判断他的准确度)
** 参数描述:time (us) 注意time<65535
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void Delay_Us(uint16_t time) //延时函数
{
uint16_t i,j;
for(i=0;i<time;i++)
for(j=0;j<9;j++);
}
lcd.c
#include "lcd.h"
//******************************************************************
//us函数
void delay_us(uint16_t us)
{
uint16_t i;
for(i=0;i<us;i++)
for(i=0;i<1000;i++)
{;}
}
//******************************************************************
//ms函数
void delay_ms(uint16_t ms)
{
uint16_t i,j,k;
for(k=0;k<ms;k++)
for(i=0;i<1000;i++)
for(j=0;j<50;j++)
{;}
}
//******************************************************************
//忙标志位检测函数
void Check_Busy(void)
{
RS=0;
RW=1;
EN=1;
GPIOA->ODR|=0xff;
while((GPIOA->ODR&0x80)==0x80);
EN=0;
}
//******************************************************************
//写命令函数
void write_com(unsigned char com)
{
// Check_Busy();
delay_ms(1);
RS=0;delay_us(10);
RW=0;delay_us(10);
EN=1;delay_us(10);
GPIO_Write(GPIOA,com); delay_ms(1);
//DataPort->ODR|=(com<<8); delay_ms(100);
EN=0;delay_us(100);
}
//******************************************************************
//写数据函数
void write_data(unsigned char ddata)
{
// Check_Busy();
delay_ms(1);
RS=1;delay_us(10);
RW=0;delay_us(10);
EN=1;delay_us(10);
GPIO_Write(GPIOA,ddata);delay_ms(1);
// DataPort->ODR|=(ddata<<8);delay_ms(100);
EN=0;delay_us(10);
}
//******************************************************************
//显示位置换算函数
void LCD_set_xy(unsigned char x,unsigned int y)
{
unsigned char addr;
switch(x)
{
case 1: addr=0x80+y;break;
case 2: addr=0x90+y;break;
case 3: addr=0x88+y;break;
case 4: addr=0x98+y;break;
default : break;
}
write_com(addr);//写命令
}
//******************************************************************
//显示初始化函数
void LCD_init(void)
{
write_com(0x34);
delay_us(10);
write_com(0x30);
delay_us(10);
write_com(0x0c);
delay_us(10);
write_com(0x01);
delay_us(10);
}
////////////////////////////////////////////
void LCD12864Configuration(void)//IO初始化
{
GPIO_InitTypeDef GPIO;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA, ENABLE);
GPIO.GPIO_Pin = RS_Pin | RW_Pin | EN_Pin;
GPIO.GPIO_Speed = GPIO_Speed_50MHz;
GPIO.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO);
//八位数据口, PA0 ~ PA7
GPIO.GPIO_Pin = 0xFF;
GPIO.GPIO_Speed = GPIO_Speed_50MHz;
GPIO.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO);
LCD_init();
}
lcd_function.c
#include "lcd_function.h"
#include "usart.h"
extern uint16_t aa[10];
//******************************************************************
//显示汉字、字符函数
void display_str(unsigned char x,unsigned char y,unsigned char *str)
{
LCD_set_xy(x,y);
while(*str)
{
write_data(*str);
str++;
delay_ms(5);
}
}
//显示函数
void LCD_Wmessage(uint8_t* message,uint8_t address)
{
write_com(address);//要显示的位置
while(*message>0)//判断内容有没有发完
{
write_data(*message); //内核还是发字节函数
message++; //慢慢发完一串指针
}
}
/******************************************************************************/
// 函数名称:Lcd12864_Brush_Screen_Dark
// 输入参数:无
// 输出参数:无
// 函数功能:全部写0(128*64个点)
//上半屏是32个行地址(00H-31H)x 8个列地址(00H-07H)
//上半屏是32个行地址(00H-31H)x 8个列地址(08H-0FH)
/******************************************************************************/
void Lcd12864_Brush_Screen_Dark(void){
uint8_t col,cnt;
uint16_t num=0;
for(col=0;col<32;col++){
write_com(0x34);//写命令(扩充指令集)
write_com(0x80+col);//列地址
write_com(0x80); //行地址,上半屏,即第一行地址0X80
write_com(0x30);//写命令(基本指令集)
for(cnt=0;cnt<16;cnt++)
write_data(0x00);//读取数据写入LCD
num+=16;
}
for(col=0;col<32;col++){
write_com(0x34);//写命令
write_com(0x80+col);//列地址
write_com(0x80+8); //行地址,下半屏,即第三行地址0X88
write_com(0x30);
for(cnt=0;cnt<16;cnt++)
write_data(0x00);//读取数据写入LCD
num+=16;
}
write_com(0x36); //扩充功能设定
write_com(0x30);//基本功能设定
}
/******************************************************************************/
//128*64点阵图形数据
/******************************************************************************/
const uint32_t imageTable[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xFC,0x00,0xFF,0xFF,0x80,0x3F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFF,0x8F,0xFF,0x7F,0xF0,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0xFF,0xFF,0x80,0x00,0x7F,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x1F,0xFF,0xFC,0x00,0x00,0x0F,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x3F,0xFF,0xE0,0x00,0x00,0x03,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x3F,0xFF,0x80,0x00,0x00,0x00,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x03,0x00,0x00,
0x7F,0xFF,0x00,0x00,0x00,0x00,0x3F,0xFF,0x80,0x00,0x00,0x00,0x00,0x03,0x00,0x00,
0x7F,0xFE,0x00,0x00,0x00,0x00,0x1F,0xFF,0x80,0x00,0x00,0x00,0x00,0x03,0x00,0x00,
0x7F,0xF8,0x00,0x00,0x00,0x00,0x0F,0xFF,0x80,0x00,0x00,0x00,0x00,0x03,0x00,0x00,
0x7F,0xF8,0x00,0x00,0x00,0x00,0x07,0xFF,0x83,0xF8,0x3F,0x0F,0xE0,0xFF,0x0F,0xC0,
0x7F,0xE0,0x00,0x00,0x00,0x00,0x03,0xFF,0x83,0xFC,0x7F,0x8F,0xF1,0xFF,0x1F,0xE0,
0x3F,0xE0,0x00,0x00,0x00,0x00,0x01,0xFF,0x83,0x8C,0x01,0x8E,0x73,0x03,0x18,0x60,
0x3F,0xC0,0x00,0x00,0x00,0x00,0x01,0xFE,0x03,0x0C,0x01,0x8C,0x33,0x03,0x18,0x60,
0x3F,0xC0,0x00,0x00,0x00,0x00,0x01,0xFE,0x03,0x0C,0x01,0x8C,0x33,0x03,0x18,0x60,
0x3F,0x80,0x0F,0x00,0x00,0x1C,0x00,0xFE,0x03,0x0C,0x3F,0x8C,0x33,0x03,0x0F,0xE0,
0x1F,0x80,0x3F,0x80,0x00,0x7E,0x00,0xFC,0x03,0x0C,0x7F,0x8C,0x33,0x03,0x1F,0xE0,
0x0F,0x80,0xFF,0xC0,0x00,0xFF,0x80,0xF8,0x03,0x0C,0xE1,0x8C,0x33,0x03,0x38,0x60,
0x07,0x01,0xFF,0xC0,0x00,0xFF,0xC0,0x70,0x03,0x0C,0xE1,0x8C,0x33,0x03,0x38,0xE0,
0x03,0x03,0xFF,0xE0,0x01,0xFF,0xE0,0x60,0x03,0xFC,0xFF,0x8C,0x31,0xFF,0x3D,0xE0,
0x03,0x03,0xFF,0xE0,0x00,0xFF,0xE0,0x60,0x03,0xFC,0x7F,0x8C,0x30,0xFF,0x1F,0xE0,
0x03,0x07,0xF1,0xC0,0x00,0xF7,0xF0,0x60,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x07,0xFF,0xC0,0x00,0xFF,0xF8,0x60,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x0F,0xFF,0xC0,0x00,0xFF,0xF8,0x60,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x0F,0xFF,0x80,0x00,0xFF,0xF8,0x60,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x0F,0xFF,0x81,0xC0,0x7F,0xF8,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x0F,0xFF,0x83,0xF8,0x7F,0xF8,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x8F,0xFF,0x07,0xF8,0x7F,0xF8,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x87,0xFF,0x07,0xF8,0x3F,0xF8,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x87,0xFE,0x03,0xF0,0x1F,0xF1,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xC3,0xFC,0x00,0x80,0x0F,0xE1,0x81,0x80,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
0x00,0xC0,0xE0,0x00,0x00,0x07,0xC1,0x81,0x80,0x0E,0x00,0x00,0x10,0x00,0x3F,0xF0,
0x00,0x60,0x00,0x00,0x00,0x00,0x03,0x03,0x30,0x06,0x0C,0x00,0x10,0x00,0x00,0x60,
0x00,0x70,0x00,0x00,0x00,0x00,0x07,0x06,0x18,0x02,0x07,0x00,0x10,0x00,0x00,0x40,
0x00,0x30,0x00,0x00,0x00,0x00,0x0E,0x0F,0xFC,0x00,0x03,0x01,0xFF,0x00,0x00,0x80,
0x00,0x1C,0x00,0x00,0x00,0x00,0x1C,0x00,0x80,0x00,0x03,0x09,0x11,0x00,0x01,0x00,
0x00,0x0E,0x00,0x00,0x00,0x00,0x38,0x01,0x00,0x1F,0x40,0x11,0x11,0x00,0x01,0x00,
0x00,0x07,0x80,0x00,0x00,0x01,0xF0,0x7F,0xFE,0x02,0x20,0x21,0xFF,0x00,0xFF,0xFE,
0x00,0x01,0xF0,0x00,0x00,0x07,0xC0,0x06,0x10,0x02,0x10,0x41,0x11,0x00,0x01,0x00,
0x00,0x00,0xFF,0xC0,0x00,0x7F,0x80,0x0C,0x08,0x02,0x08,0x81,0x11,0x00,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x80,0x1B,0xE4,0x02,0x45,0x01,0xFF,0x00,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x80,0x70,0x03,0x82,0x82,0x00,0x10,0x00,0x01,0x00,
0x00,0x00,0xFF,0xE0,0x01,0xFF,0x80,0xC0,0x00,0x03,0x85,0x00,0x10,0x10,0x09,0x00,
0x00,0x00,0xFF,0xE0,0x01,0xFF,0x80,0x07,0xF8,0x03,0x08,0x80,0x10,0x10,0x05,0x00,
0x00,0x00,0x7F,0xE0,0x01,0xFF,0x80,0x00,0x00,0x03,0x10,0x40,0x10,0x10,0x03,0x00,
0x00,0x00,0x6F,0xC0,0x01,0xFD,0x80,0x00,0x00,0x03,0x20,0x20,0x1F,0xF0,0x01,0x00,
0x00,0x00,0x6F,0xC0,0x01,0xFD,0x80,0x3F,0xFE,0x02,0x40,0x1C,0x00,0x00,0x00,0x00,
0x00,0x00,0x60,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x60,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0xD8,0x00,0x00,0x00,0x00,
0x00,0x00,0x70,0x00,0x00,0x03,0x00,0x00,0x00,0x0C,0x00,0xD8,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0x00,0x00,0x07,0x00,0x00,0x00,0x0C,0x00,0xD8,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x00,0x00,0x0E,0x1F,0x9F,0x8F,0xDC,0x78,0xD9,0x80,0xF8,0xF1,0xFF,
0x00,0x00,0x3F,0x00,0x00,0x5E,0x1F,0x9F,0x8F,0xDE,0xFC,0xDB,0x81,0xFD,0xFD,0xFF,
0x00,0x00,0x1F,0x80,0x00,0x7E,0x19,0x99,0x8C,0xCC,0xCC,0xDF,0x01,0x8D,0x8D,0x99,
0x00,0x00,0x1F,0xFF,0xDF,0xFC,0x19,0x99,0x8C,0xCC,0x0C,0xDE,0x01,0x81,0x8D,0x99,
0x00,0x00,0x1F,0xFF,0xFF,0xFC,0x19,0x99,0x8C,0xCC,0xFC,0xDF,0x01,0x81,0x8D,0x99,
0x00,0x00,0x0F,0xF4,0x07,0xFC,0x19,0x99,0x8C,0xCC,0xCC,0xDB,0x01,0x8D,0x8D,0x99,
0x00,0x00,0x0F,0xF0,0x03,0xF8,0x19,0x99,0x8C,0xCC,0xCC,0xD9,0x99,0x8D,0x8D,0x99,
0x00,0x00,0x03,0xF0,0x01,0xF0,0x1F,0x9F,0x8F,0xCE,0xFC,0xD9,0x98,0xFC,0xF9,0x99,
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/******************************************************************************/
// 函数名称:Lcd12864_Show_Image
// 输入参数:无
// 输出参数:无
// 函数功能:显示图片
/******************************************************************************/
void Lcd12864_Show_Image(void){
// uint8_t x,y,i;
// uint16_t tmp=0;
// for(i=0;i<9;){ //分两屏,上半屏和下半屏,因为起始地址不同,需要分开
// for(x=0;x<32;x++){ //32行
// write_com(0x34);
// write_com(0x80+x);//列地址
// write_com(0x80+i); //行地址,下半屏,即第三行地址0X88
// write_com(0x30);
// for(y=0;y<16;y++)
// {
// write_data(imageTable[tmp+y]);//读取数据写入LCD
// tmp+=16;
// }
// }
// i+=8;
// }
// write_com(0x36); //扩充功能设定
// write_com(0x30);
uint8_t a,b,c;
uint16_t temp;
a=0;
for(b=0;b<32;b++) //给LCD的上或者下半屏的32行写数据
{
write_com(0x34);//写指令,扩充指令集
write_com(0x80+a);//将屏幕的首地址0x80,确定行地址,从第一行开始
write_com(0x80+b);//确定列地址
write_com(0x34);//写指令,基本指令集
for(c=0;c<16;c++)//将数组的里的8位数据写入128/8=16每行包含的16个数据位里
{
write_data(imageTable[temp+c]);//
}
temp+=16;//temp+=16 等价于temp=temp+16
}
a=8;//a+=b 等价于a=a+b
}
void chaoshenbo_LCDdisplay(void)//显示AD电压
{
display_str(1,0," 超声波采集界面");
display_str(3,0,"距离值:");
display_str(3,7,"CM");
}
//******************************************************************
////显示数字函数
//void display_data(unsigned char x,unsigned char y, unsigned int dat)
//{
// LCD_set_xy(x,y);
// delay_ms(1);
// write_data(dat+0x30);
// delay_ms(1);
//// write_data(dat/1000+0x30);
//// delay_ms(1);
//// write_data(dat%1000/100+0x30);
//// delay_ms(1);
//// write_data(dat%100/10+0x30);
//// delay_ms(1);
//// write_data(dat%10+0x30);
//// delay_ms(1);
//// write_data(' ');
//// delay_ms(1);
//}
//void ADC_LCDdisplay(void)//显示AD电压
//{
//
//
// dianya = (ADC_ConverValue/4096*3.3)*1000;//计算出AD转换后的电压值乘以1000方便取位
//
//// disbuff[1]= dianya / 1000; //个位
//// disbuff[2] = (dianya % 1000) / 100; //小数一位
//// disbuff[3] = ((dianya % 1000) % 100) / 10; //小数二位
//// disbuff[4]= ((dianya % 1000) % 100) % 10; //小数三位
//}
|