亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码
標題:
單片機控制LCD1602顯示電壓和角度值的代碼
[打印本頁]
作者:
samo_xyh
時間:
2018-8-30 16:23
標題:
單片機控制LCD1602顯示電壓和角度值的代碼
LCD1602
單片機源程序如下:
#include "include.h"
//LCD1602
/********IO引腳定義***********************************************************/
sbit LCD_RS=P1^0;//定義引腳
sbit LCD_RW=P1^1;
sbit LCD_E=P1^2;
/********宏定義***********************************************************/
#define LCD_Data P0
#define Busy 0x80 //用于檢測LCD狀態字中的Busy標識
/********數據定義*************************************************************/
//unsigned char code uctech[] = {"MCU218"};
/***********主函數開始********************************************************/
/*
void main(void)
{
Delay400Ms(); //啟動等待,等LCD講入工作狀態
LCDInit(); //初始化
Delay5Ms(); //延時片刻(可不要)
DisplayListChar(0, 0, uctech);
DisplayOneChar(4, 1, 'a');
ReadDataLCD(); //測試用句無意義
while(1);
}
*/
/***********寫數據********************************************************/
void WriteDataLCD(unsigned char WDLCD)
{
ReadStatusLCD(); //檢測忙
LCD_Data = WDLCD;
LCD_RS = 1;
LCD_RW = 0;
LCD_E = 0; //若晶振速度太高可以在這后加小的延時
LCD_E = 0; //延時
LCD_E = 1;
}
/***********寫指令********************************************************/
void WriteCommandLCD(unsigned char WCLCD,BuysC) //BuysC為0時忽略忙檢測
{
if (BuysC) ReadStatusLCD(); //根據需要檢測忙
LCD_Data = WCLCD;
LCD_RS = 0;
LCD_RW = 0;
LCD_E = 0;
LCD_E = 0;
LCD_E = 1;
}
/***********讀數據********************************************************/
unsigned char ReadDataLCD(void)
{
LCD_RS = 1;
LCD_RW = 1;
LCD_E = 0;
LCD_E = 0;
LCD_E = 1;
return(LCD_Data);
}
/***********讀狀態*******************************************************/
unsigned char ReadStatusLCD(void)
{
LCD_Data = 0xFF;
LCD_RS = 0;
LCD_RW = 1;
LCD_E = 0;
LCD_E = 0;
LCD_E = 1;
while (LCD_Data & Busy); //檢測忙信號
return(LCD_Data);
}
/***********初始化********************************************************/
void LCDInit(void)
{
LCD_Data = 0;
WriteCommandLCD(0x38,0); //三次模式設置,不檢測忙信號
Delay5Ms();
WriteCommandLCD(0x38,0);
Delay5Ms();
WriteCommandLCD(0x38,0);
Delay5Ms();
WriteCommandLCD(0x38,1); //顯示模式設置,開始要求每次檢測忙信號
WriteCommandLCD(0x08,1); //關閉顯示
WriteCommandLCD(0x01,1); //顯示清屏
WriteCommandLCD(0x06,1); //顯示光標移動設置
WriteCommandLCD(0x0C,1); //顯示開及光標設置
}
/***********按指定位置顯示一個字符*******************************************/
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
if (Y) X |= 0x40; //當要顯示第二行時地址碼+0x40;
X |= 0x80; //算出指令碼
WriteCommandLCD(X, 0); //這里不檢測忙信號,發送地址碼
WriteDataLCD(DData);
}
/***********按指定位置顯示一串字符*****************************************/
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
{
unsigned char ListLength;
ListLength = 0;
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
while (DData[ListLength]>=0x20){ //若到達字串尾則退出
if (X <= 0xF){ //X坐標應小于0xF
DisplayOneChar(X, Y, DData[ListLength]); //顯示單個字符
ListLength++;
X++;
}
}
}
/***********短延時********************************************************/
void Delay5Ms(void)
{
unsigned int TempCyc = 5552;
while(TempCyc--);
}
/***********長延時********************************************************/
void Delay400Ms(void)
{
unsigned char TempCycA = 5;
unsigned int TempCycB;
while(TempCycA--)
{
TempCycB=7269;
while(TempCycB--);
}
}
//顯示AD轉換值
void display_AD_value(unsigned int result)
{
int i=0;
unsigned int temp=0;
unsigned char str[3];
unsigned int j=100;
unsigned char k=0;
DisplayOneChar(0, 0, 'U'); //顯示單個字符
DisplayOneChar(1, 0, '='); //顯示單個字
DisplayOneChar(6, 0, 'V'); //顯示單個字符
for(i=0; i<=2; i++)
{
temp=result/j;
result=result-j*temp;
str[i]=(unsigned char)(temp+0x30);
j/=10;
}
for(k=0,i=0; i<4; k++,i++)
{
if(i==0)
DisplayOneChar(k+2, 0, str[i]); //顯示單個字符
else if(i==1)
DisplayOneChar(k+2, 0, '.'); //顯示單個字符
else
{
DisplayOneChar(k+2, 0, str[i-1]); //顯示單個字符
}
}
}
//顯示電機轉動角度
void display_motor_rotaition(unsigned int result)
{
int i=0;
unsigned int temp=0;
unsigned char str[4];
unsigned int j=1000;
unsigned char k=0;
DisplayOneChar(0, 1, 'A'); //顯示單個字符
DisplayOneChar(1, 1, 'n'); //顯示單個字
DisplayOneChar(2, 1, 'g'); //顯示單個字符
DisplayOneChar(3, 1, '='); //顯示單個字符
DisplayOneChar(9, 1, 'd'); //顯示單個字符
DisplayOneChar(10, 1, 'u'); //顯示單個字符
for(i=0; i<=3; i++)
{
temp=result/j;
result=result-j*temp;
str[i]=(unsigned char)(temp+0x30);
j/=10;
}
for(k=0,i=0; i<5; k++,i++)
{
if(i==4)
DisplayOneChar(k+4, 1, str[i-1]); //顯示單個字符
else if(i==3)
DisplayOneChar(k+4, 1, '.'); //顯示單個字符
else
{
DisplayOneChar(k+4, 1, str[i]); //顯示單個字符
}
}
}
復制代碼
所有資料51hei提供下載:
LCD1602.rar
(8.88 KB, 下載次數: 13)
2018-8-30 16:21 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
admin
時間:
2018-8-30 17:04
補全原理圖或者詳細說明一下電路連接即可獲得100+黑幣
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1