#include
#include"intrins.h"
//==========================================================
sbit CS=P3^0; //Enable chip select
sbit CLK=P3^1; //Clock
sbit Do=P3^2; //Data output
sbit Di=P3^2; //Data input
sbit Do2=P3^3; //Data output
sbit Di2=P3^3; //Data input
sbit Do3=P3^4; //Data output
sbit Di3=P3^4; //Data input
sbit Do4=P3^5; //Data output
sbit Di4=P3^5; //Data input
sbit Do5=P3^6; //Data output
sbit Di5=P3^6; //Data input
unsigned char data_f=0,data_c=0,data_f2=0,data_c2=0,data_f3=0,data_c3=0,data_f4=0,data_c4=0,data_f5=0,data_c5=0; //data_f正确顺序 data_c逆序
unsigned char last[5]; //Record the value obtained by each AD conversion at the last moment
unsigned char current[5]; //Record the value obtained by this AD conversion
int left = 0; //Record the number of steps the motor takes to the left within 0.1 seconds
int right = 0; //Record the number of steps the motor takes to the right within 0.1 seconds
sbit RS = P2^4;//Pin4
sbit RW = P2^5; //Pin5
sbit E = P2^6;//Pin6
#define Data P0 //Data port
char data TimeNum[]=" ";
char data Test1[]=" ";
/******************************************************************/
/* 函数声明 */
/******************************************************************//***************************************************************/
void DelayUs(unsigned char us)//delay us
{
unsigned char uscnt;
uscnt=us>>1;/* Crystal frequency in 12MHz*/
while(--uscnt);
}
/******************************************************************/
void DelayMs(unsigned int ms)//delay Ms
{
while(--ms)
{
DelayUs(250);
DelayUs(250);
DelayUs(250);
DelayUs(250);
}
}
void WriteCommand(unsigned char c)
{
DelayMs(5);//short delay before operation
E=0;
RS=0;
RW=0;
_nop_();
E=1;
Data=c;
E=0;
}
/****************************************************************/
void WriteData(unsigned char c)
{
DelayMs(5); //short delay before operation
E=0;
RS=1;
RW=0;
_nop_();
E=1;
Data=c;
E=0;
RS=0;
}
/*********************************************************************/
void ShowChar(unsigned char pos,unsigned char c)
{
unsigned char p;
if (pos>=0x10)
p=pos+0xb0; //是第二行则命令代码高4位为0xc
else
p=pos+0x80; //是第二行则命令代码高4位为0x8
WriteCommand (p);//write command
WriteData (c); //write data
}
/*************************************************************************/
void ShowString (unsigned char line,char *ptr)
{
unsigned char l,i;
l=line<<4;
for (i=0;i<16;i++)
ShowChar (l++,*(ptr+i));//循环显示16个字符
}
/*********************************************************************/
void InitLcd()
{
DelayMs(15);
WriteCommand(0x38); //display mode
WriteCommand(0x38); //display mode
WriteCommand(0x38); //display mode
WriteCommand(0x06); //显示光标移动位置
WriteCommand(0x0c); //显示开及光标设置
WriteCommand(0x01); //显示清屏
}
///
...
//
Pre
-
initialization
=
...
CS=1;
_nop_();
CS=0;
Di=1;
Di2=1;
Di3=1;
Di4=1;
Di5=1;
//=================================================================
//The first falling edge======================================================
CLK
=1;
_nop_
();
_nop_
(
)
;
CLK
=
0
;
//
=
...
_nop_();
CLK=0;
//======================================================================
//The third falling edge==========================================================
_nop_();
_nop_();
CLK=1;
Di=0;
Di2=1;
Di3=1;
Di4=1;
Di5=1;
_nop_();
_nop_();
CLK=0;
//
AD initialization
completed
//
======================================================================
//
Read
data
=
...
CLK=1;
CLK=1;
_nop_();
_nop_();
CLK=0;
CLK=1;
//Get a normal sorted 8-bit data
for(i=8;i>0;i--)
{
data_f<<=1;
data_f2<<=1;
data_f3<<=1;
data_f4<<=1;
data_f5<<=1;
data_f|=Do;
data_f2|=Do2;
data_f3|=Do3;
data_f4|=Do4;
data_f5|=Do5;
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
}
//==============================
//Get an 8-bit data in reverse order
for(i=8;i>0;i--)
{
data_c<<=1;
data_c2<<=1;
data_c3<<=1;
data_c4<<=1;
data_c5<<=1;
data_c|=Do;
data_c2|=Do2;
data_c3|=Do3;
data_c4|=Do4;
data_c5|=Do5;
_nop_();
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
}
//==============================
CLK=0;
_nop_();
_nop_();
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
_nop_();
CLK=1;
_nop_();
CS=1;
_nop_();
_nop_();
}
//===================================================================
//Display conversion==============================================================
char huanhuan(unsigned char benben)
{
switch(benben)
{
case 0:
return '0';
break;
case 1:
return '1';
break;
case 2:
return '2';
break;
case 3:
return '3';
break;
case 4:
return '4';
break;
case 5:
return '5';
break;
case 6:
return '6';
break;
case 7:
return '7';
break;
case 8:
return '8';
break;
case 9:
return '9';
break;
default:
break;
}
}
//===================================================================
void main()
{
unsigned xianshi=0;
InitLcd();
DelayMs(15);
sprintf(Test1," wo shi tiancai ");//the first line
ShowString(0,Test1);
sprintf(TimeNum,"AD value is ");//the first line
ShowString(1,TimeNum);
while(1)
{
DelayMs(800);
xianshi=data_f;
ADconv();
TimeNum[12]=huanhuan(xianshi/100);
TimeNum[13]=huanhuan(xianshi/10%10);
TimeNum[14]=huanhuan(xianshi%10);
ShowString(1,TimeNum);
}
}
Previous article:Summary of AT89C51ED2 EEPROM read and write operations
Next article:The use of 51 single chip microcomputer 24c02
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- MCU Principles and Interface Technology C51 Programming (Edited by Zhang Yigang)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- ATMega48 Bootloader Software Practical Method
- 【NUCLEO-WL55JC2 Review 1】 Overview of STM32WL Chip
- Friends who are familiar with MP2307DN, please take a look!
- Design of wireless communication controller for GPRS data transmission service
- General welding specifications for MINI manufacturers
- Why constant current source simulation does not produce constant current
- Discuss the strategy of converting the Allegro package library from a high version to a low version.
- [National Technology N32G457 Review] 1. Unboxing + Lighting
- The second article is a simple comparison between GD32VF103C START and ST official routines
- [GD32L233C-START Review] Part 3 PWM driving breathing light