久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標(biāo)題:
LCD12864顯示字符或數(shù)字程序,顯示數(shù)字函數(shù)可以顯示大于0的整數(shù),小數(shù),負(fù)數(shù)
[打印本頁]
作者:
蘭小方
時(shí)間:
2017-7-29 12:28
標(biāo)題:
LCD12864顯示字符或數(shù)字程序,顯示數(shù)字函數(shù)可以顯示大于0的整數(shù),小數(shù),負(fù)數(shù)
程序里面的void Transmit_Display( u8 x, u8 y, float tiggtal, int N)函數(shù)只需把參數(shù)傳進(jìn)去,x,y是控制顯示坐標(biāo),最后一個(gè)是控制保留小數(shù)點(diǎn)后面幾位小數(shù),
自帶數(shù)組顯示函數(shù)和字符串顯示函數(shù)
單片機(jī)源程序如下:
#include "lcd12864.h"
#include "delay.h"
#include "GPIO_Int.h"
#include "math.h"
#include "usart.h"
/*********************************************
數(shù)據(jù)讀寫端口
*********************************************/
void Lcd_Send_Date(u8 date)
{
u8 i;
LCD_RS=1;
for(i=0;i<8;i++)
{
if((date<<i)&0x80)
{
LCD_RW=1;
}
else
{
LCD_RW=0;
}
LCD_EN=0;
LCD_EN=1;
}
}
/***********************************************
寫入命令
***********************************************/
void Write_Cmd(u8 com)
{
Lcd_Send_Date(0xf8);
Lcd_Send_Date(0xf0&com);
Lcd_Send_Date(com<<4);
delay_ms(1);
}
/***********************************************
寫入數(shù)據(jù)
***********************************************/
void Write_Data(u8 dat)
{
Lcd_Send_Date(0xfa);
Lcd_Send_Date(dat&0xf0);
Lcd_Send_Date(dat<<4);
delay_ms(1);
}
/***********************************************
液晶屏初始化
***********************************************/
void Init_ST7920()
{
delay_ms(40); //大于40MS的延時(shí)程序
Write_Cmd(0x30); //選擇基本指令集
Write_Cmd(0x40); //對CGRAM第一個(gè)自定義字符操作,
delay_us(100); //延時(shí)大于100us
Write_Cmd(0x30); //選擇8bit數(shù)據(jù)流
delay_us(40); //延時(shí)大于37us
Write_Cmd(0x0c); //開顯示(無游標(biāo)、不反白)
delay_us(100); //延時(shí)大于100us
Write_Cmd(0x01); //清除顯示,并且設(shè)定地址指針為00H
delay_ms(15); //延時(shí)大于10ms
Write_Cmd(0x06); //指定在資料的讀取及寫入時(shí),設(shè)定游標(biāo)的移動(dòng)方向及指定顯示的移位,光標(biāo)從右向左加1位移動(dòng)
delay_us(100); //延時(shí)大于100us
}
void Display_Count(u8 x,u8 y,u8 data)
{
switch(data)
{
case 0:LCD_DisplayInit(x,y,"零");
break;
case 1:LCD_DisplayInit(x,y,"一");
break;
case 2:LCD_DisplayInit(x,y,"二");
break;
case 3:LCD_DisplayInit(x,y,"三");
break;
case 4:LCD_DisplayInit(x,y,"四");
break;
default: break;
}
}
/***********************************************
顯示字符串
x:橫坐標(biāo)值,范圍0~8
y:縱坐標(biāo)值,范圍1~4
***********************************************/
void LCD_Struct_Display( LCD_DisplayTypedef *Display_Structure )
{
switch(Display_Structure->ordinate)
{
case 1: Write_Cmd(0x80+( (Display_Structure->abscissa) -1) );break;
case 2: Write_Cmd(0x90+( (Display_Structure->abscissa) -1) );break;
case 3: Write_Cmd(0x88+( (Display_Structure->abscissa) -1) );break;
case 4: Write_Cmd(0x98+( (Display_Structure->abscissa) -1) );break;
default: break;
}
while(*( Display_Structure->character_string ) != '\0')
{
if((*( Display_Structure->character_string )) == 'n')
{
USART_RX_STA = 0;
break;
}
Write_Data( (*( Display_Structure->character_string )) );
( Display_Structure->character_string )++;
delay_us(50);
}
}
/********************************************************
普通在LCD顯示字符
*******************************************************/
void LCD_DisplayInit(u8 x, u8 y,u8 *spr)
{
LCD_DisplayTypedef LCD_DisplayStructure;
LCD_DisplayStructure.abscissa = x;
LCD_DisplayStructure.ordinate = y;
LCD_DisplayStructure.character_string = spr;
LCD_Struct_Display(&LCD_DisplayStructure);
}
/***********************************************
顯示串口接收的字符串
向串口發(fā)送x,y,"字符串"
***********************************************/
void USART1_ReceiveInit(u8 *USART1_Buffer)
{
LCD_DisplayTypedef LCD_DisplayStructure;
LCD_DisplayStructure.abscissa = (*USART1_Buffer - 48);
LCD_DisplayStructure.ordinate = (*(USART1_Buffer+2) - 48);
LCD_DisplayStructure.character_string = USART1_Buffer+4;
LCD_Struct_Display(&LCD_DisplayStructure);
}
/****************************************************************
********進(jìn)行數(shù)字轉(zhuǎn)換輸出到LCD顯*********
******************************************************************/
/***************************************************************
計(jì)算并返回小數(shù)點(diǎn)的位置
***************************************************************/
int Radix_point(float value)
{
int medium_int = 0, count_RP = 0;
medium_int = (int)value;
if(value == 0)
{
return count_RP;
}
if(value < 0)
{
value = (-value);
}
if(medium_int > 0)
{
while(medium_int)
{
count_RP++;
medium_int /= 10;
}
return count_RP;
}
else
{
while(!medium_int)
{
value *= 10;
medium_int = (int)(value);
count_RP++;
}
return count_RP;
}
}
/*********************************************************
把FLOAT型書轉(zhuǎn)換成INT型返回出去
***********************************************************/
int Transform_val(float val, int N)
{
int value = 0;
if(val < 0)
{
val = (-val);
}
if(val >= 1 )
{
value = (int)(val)*pow(10,N) + (int)((val - (int)(val))*pow(10,N));
}
else
if(1>val > 0)
{
value = (int)((val)*pow(10,N));
}
return value;
}
/******************************************************************
數(shù)字顯示函數(shù)
*******************************************************************/
void Display_number(int channel_first, float channel_scond)
{
int current=1, val, count = 1, i = 0, j = 0;
float medium_float;
j = (Radix_point(channel_scond)) - 1;
val = channel_first;
if(channel_scond < 0)
{
medium_float = (-channel_scond);
}
else
{
medium_float = channel_scond;
}
while( (val>=10) )
{
val /= 10;
count *= 10;
}
if(channel_scond < 0)
{
Write_Data('-');
}
if(medium_float >= 1)
{
while(count)
{
if(Radix_point(medium_float) == i)
{
Write_Data('.');
current = 0;
i = 0;
}
else
{
Write_Data('0' + (channel_first/count%10));
count /=10;
if(current)
i++;
}
}
}
else
if(medium_float > 0)
{
Write_Data('0');
Write_Data('.');
while(j > 0)
{
Write_Data('0');
j--;
}
while(count)
{
Write_Data('0' + (channel_first/count%10));
count /=10;
}
}
else
if(medium_float == 0)
{
Write_Data('0');
}
}
/***************************************************************
數(shù)字傳送顯示
**************************************************************/
void Transmit_Display( u8 x, u8 y, float tiggtal, int N)
{
switch(y)
{
case 1: Write_Cmd(0x80+ (x -1)) ;break;
case 2: Write_Cmd(0x90+ (x -1)) ;break;
case 3: Write_Cmd(0x88+ (x -1)) ;break;
case 4: Write_Cmd(0x98+ (x -1)) ;break;
default: break;
}
Display_number(Transform_val(tiggtal,N),tiggtal);
}
復(fù)制代碼
LCD12864.h
#ifndef _LCD12864_H_
#define _LCD12864_H_
#include "sys.h"
/******定義一個(gè)結(jié)構(gòu)體******/
typedef struct
{
u8 USART1_DiaplayEnable;
u8 abscissa; //x
u8 ordinate; //y
u8 *character_string;
}LCD_DisplayTypedef;
/**************************/
void Write_Cmd(u8 com);
void Write_Data(u8 dat);
void Init_ST7920(void);
void Display_Count(u8 x,u8 y,u8 data);
/* 結(jié)構(gòu)體顯示 */
void LCD_DisplayInit(u8 x, u8 y,u8 *spr);
void LCD_Struct_Display( LCD_DisplayTypedef *Display_Structure );
/* 串口接收顯示 */
void USART1_ReceiveInit(u8 *USART1_Buffer);
/* 數(shù)字傳送顯示 */
void Transmit_Display( u8 x, u8 y, float tiggtal, int N);
#endif
復(fù)制代碼
作者:
danpianji80c51
時(shí)間:
2017-7-30 11:09
謝謝樓主分享
作者:
51hww34
時(shí)間:
2017-7-30 20:57
學(xué)習(xí)學(xué)習(xí) 感謝分享
作者:
yilantinglengyu
時(shí)間:
2018-4-15 12:04
xaingxiazai
作者:
ppokwsx
時(shí)間:
2018-5-24 18:05
謝謝分享
作者:
大海的胸懷
時(shí)間:
2021-6-22 14:08
不能用啊
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
国产一级淫片免费视频
|
久久久91精品国产一区二区三区
|
91免费在线视频
|
国产高清一区二区
|
在线观看国产视频
|
99视频在线免费观看
|
日韩av第一页
|
午夜免费
|
免费的av网站
|
国产乱码久久久久久
|
一区二区三区精品视频
|
日本成人久久
|
国产专区视频
|
国产精品网址
|
久热9
|
91在线导航
|
亚洲欧洲av在线
|
国产美女福利在线观看
|
国产乱码高清区二区三区在线
|
一区二区三区精品
|
精品欧美一区二区精品久久久
|
久久毛片网站
|
青青操av
|
欧美一级小视频
|
色橹橹欧美在线观看视频高清
|
色黄爽
|
www.9191
|
日本污视频
|
国产又爽又黄的视频
|
欧美6一10sex性hd
|
一区二区三区视频在线观看
|
国产视频久
|
99精品欧美一区二区蜜桃免费
|
国外成人在线视频
|
亚洲成人在线网
|
国产高潮好爽受不了了夜色
|
91在线看视频
|
亚洲日本乱码在线观看
|
91免费入口
|
波多野结衣中文字幕一区二区三区
|
色爱综合网
|