久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
LCD12864顯示字符或數字程序,顯示數字函數可以顯示大于0的整數,小數,負數
[打印本頁]
作者:
蘭小方
時間:
2017-7-29 12:28
標題:
LCD12864顯示字符或數字程序,顯示數字函數可以顯示大于0的整數,小數,負數
程序里面的void Transmit_Display( u8 x, u8 y, float tiggtal, int N)函數只需把參數傳進去,x,y是控制顯示坐標,最后一個是控制保留小數點后面幾位小數,
自帶數組顯示函數和字符串顯示函數
單片機源程序如下:
#include "lcd12864.h"
#include "delay.h"
#include "GPIO_Int.h"
#include "math.h"
#include "usart.h"
/*********************************************
數據讀寫端口
*********************************************/
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);
}
/***********************************************
寫入數據
***********************************************/
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的延時程序
Write_Cmd(0x30); //選擇基本指令集
Write_Cmd(0x40); //對CGRAM第一個自定義字符操作,
delay_us(100); //延時大于100us
Write_Cmd(0x30); //選擇8bit數據流
delay_us(40); //延時大于37us
Write_Cmd(0x0c); //開顯示(無游標、不反白)
delay_us(100); //延時大于100us
Write_Cmd(0x01); //清除顯示,并且設定地址指針為00H
delay_ms(15); //延時大于10ms
Write_Cmd(0x06); //指定在資料的讀取及寫入時,設定游標的移動方向及指定顯示的移位,光標從右向左加1位移動
delay_us(100); //延時大于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:橫坐標值,范圍0~8
y:縱坐標值,范圍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);
}
/***********************************************
顯示串口接收的字符串
向串口發送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);
}
/****************************************************************
********進行數字轉換輸出到LCD顯*********
******************************************************************/
/***************************************************************
計算并返回小數點的位置
***************************************************************/
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型書轉換成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;
}
/******************************************************************
數字顯示函數
*******************************************************************/
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');
}
}
/***************************************************************
數字傳送顯示
**************************************************************/
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);
}
復制代碼
LCD12864.h
#ifndef _LCD12864_H_
#define _LCD12864_H_
#include "sys.h"
/******定義一個結構體******/
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);
/* 結構體顯示 */
void LCD_DisplayInit(u8 x, u8 y,u8 *spr);
void LCD_Struct_Display( LCD_DisplayTypedef *Display_Structure );
/* 串口接收顯示 */
void USART1_ReceiveInit(u8 *USART1_Buffer);
/* 數字傳送顯示 */
void Transmit_Display( u8 x, u8 y, float tiggtal, int N);
#endif
復制代碼
作者:
danpianji80c51
時間:
2017-7-30 11:09
謝謝樓主分享
作者:
51hww34
時間:
2017-7-30 20:57
學習學習 感謝分享
作者:
yilantinglengyu
時間:
2018-4-15 12:04
xaingxiazai
作者:
ppokwsx
時間:
2018-5-24 18:05
謝謝分享
作者:
大海的胸懷
時間:
2021-6-22 14:08
不能用啊
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
国产农村一级片
|
亚洲欧美中文日韩在线v日本
|
91精品国产欧美一区二区
|
国产日韩精品在线
|
热久色
|
日韩久久精品
|
国产精品中文字幕在线
|
国产精品国产三级国产aⅴ中文
|
国产成人精品一区二区三区
|
性做久久久久久免费观看欧美
|
亚洲成人免费
|
久久的色
|
久久午夜国产精品www忘忧草
|
国外成人免费视频
|
www.色53色.com
|
九九福利
|
欧美日韩a
|
国产高清视频一区
|
麻豆精品国产91久久久久久
|
91看片在线观看
|
国产精品欧美一区二区三区不卡
|
亚洲图片一区二区三区
|
成人免费在线网
|
91精品国产综合久久久久蜜臀
|
亚洲一区国产
|
亚洲一区二区三区福利
|
久草在线
|
人人天天操
|
亚洲精品福利在线
|
视频一区二区中文字幕日韩
|
精品毛片
|
在线观看国产视频
|
亚洲欧美bt
|
亚洲一在线
|
黄色片在线看
|
国产精品入口麻豆www
|
麻豆av网
|
中文字幕精品一区二区三区在线
|
亚洲高清三级
|
欧美一区二区免费在线
|
成人久久18免费网站麻豆
|