Download the header file STC12C5A.H: http://www.51hei.com/mcu/2564.html
#include
#include "stdio.h"
#include "LCD1602.h"
#include "interrupt.h"
#include "chiclet_keyboard.h"
#define uchar unsigned char
#define uint unsigned int
void main()
{
delay(500);
LCD_init();
interrupts_init();
chiclet_keyboard_();
EA=0;
while(1);
}
#ifndef _LCD1602_H
#define _LCD1602_H
/*
MCU: STC89CXX, Crystal: 12M Compiler: KEIL uVision4
LCD1602 Command Code:
Code Description
1 Clear display
2 Cursor reset
Input mode selection:
X 0000 01(I/D)S
I/D: Cursor movement direction, 1 right, 0 left
S: Whether the screen text moves. 1 move.
Display on/off control:
X 0000 1DCB
D: Overall display switch, 1 is on
C: Cursor switch, 1 is on
B: Cursor flashing, 1 is flashing
Cursor or character shift:
X 0001 (S/C)(R/L)**
S/C: 1 moves text, 0 moves cursor
R/L: 1 is right, 0 is left
Function setting:
X 001(DL) NF**
DL: 1 is 8-line mode, 0 is 4-line mode
N: 0 is single line display, 1 is 2 lines display
F: 0 is 5X7 characters, 1 is 5X10 characters
Character address:
X 01xx xxxx
xxxxx: corresponding ASCII address
Display address:
X 1xxx xxxx
xxx xxxx: screen display address
Internal display and screen address correspondence note:
00--0x0F corresponds to the first line of the screen, 00--0x27 internal first line
0x40--0x4F corresponds to the second line of the screen, 0x40--0x67 internal second line
*/
#define uchar unsigned char
#define uint unsigned int
//Define hardware interface
#define LCD_DATA P0
sbit LCD_EN=P2^5;
sbit LCD_RS=P2^3;
sbit LCD_RW=P2^4;
/**************************************************
Function name:
Function function:
Function call:
Input parameters:
Output parameters:
Copyright information:
Time version: V1.0
***************************************************/
/**************************************************
Function name: delay_ms(uint num)
Function function: delay
Function call:
Input parameter: msOutput
parameter:
Copyright information:
TimeVersion: V1.0Remarks
: Crystal: 12M
***************************************************/
void delay_ms(uint temp)
{
uint x,y;
for(x=temp;x>0;x--)
for(y=110;y>0;y--);
}
/**************************************************
Function name: write_com(uchar com)
Function function: write command
Function call: delay_ms(uint num)
Input parameter: Command code
Output parameter:
Copyright information:
TimeVersion: V1.0
***********************************************/
void LCD_w_com(uchar com)
{
LCD_RS=0;
LCD_RW=0;
LCD_DATA=com;
delay_ms(5);
LCD_EN=1;
delay_ms(5);
LCD_EN=0;
}[page]
/**********************************************
Function name: write_data(uchar date)
Function function: write data
Function call: delay_ms(uint num)
Input parameter: data
Output parameter:
copyright information:
time version: V1.0
***********************************************/
void LCD_w_data(uchar dat)
{
LCD_RS=1;
LCD_RW=0;
LCD_DATA=dat;
delay_ms(5);
LCD_EN=1;
delay_ms(5);
LCD_EN=0;
}
/**********************************************
Function name:
Function function: LCD_init()
Function call: LCD_w_com()
Input parameter:
Output parameter:
Copyright information:
Time Version: V1.0
***************************************************/
void LCD_init()
{
LCD_EN=0;
LCD_w_com(0x38); //8 lines, 2 rows, 5X7 character mode
LCD_w_com(0x0c); //Display on, cursor not displayed, cursor not blinking
LCD_w_com(0x06); //Cursor right move, text not moving
LCD_w_com(0x01); //Clear display, cursor reset
}
/**************************************************
Function name: LCD_disp_cher(uchar x,uchar y,uchar *p)
Function function: Display string at specified position
Function call: LCD_w_com(), LCD_w_data()
Input parameters: x, y coordinates, string pointer array
Output parameters:
Copyright information :
Time version: V1.0
Note: x is column, x<16, y is row, y<2. String length + x is not greater than 16.
***********************************************/
void LCD_disp_cher(uchar x,uchar y,uchar *p)
{
if(y==1)
{
LCD_w_com(0x80+x);
while(*p)
{
LCD_w_data(*p);
p++;
}
}
if(y==2)
{
LCD_w_com(0x80+0x40+x);
while(*p)
{
LCD_w_data(*p);
p++;
}
}
}
#endif//end LCD1602.H
#ifndef _interrupt_H_
#define _interrupt_H_
#define uint unsigned int
#define uchar unsigned char
uint sec=10;
sbit sb=P1^0;
sbit si=P1^1;
void interrupts_init()
{
EA=1; //enable global interrupt
ET0=1; //T0 (timer interrupt 0) overflow interrupt enable bit
TR0=1; //0 run control bit
TMOD=0x1; //16-bit timer
TH0=(65536-50000)/255;
TL0=(65536-50000)%255;
}
void ghjfgf() interrupt 1
{
uint subtle;
TH0=(65536-50000)/255;
TL0=(65536-50000)%255;
subtle++;
if(subtle==20)
{
subtle=0;
sec--;
}
}
#endif
#ifndef _chiclet_keyboard_H_
#define _chiclet_keyboard_H_
sbit S1=P3^4; //Independent buttons S1~S4
sbit S2=P3^5;
sbit S3=P3^6;
sbit S4=P3^7; //Use the reset button to exit to save keystrokes
void delay(uint ms) //Delay
{
uchar mus;
for(ms; ms>0; ms--)
for(mus=110; mus>0; mus--);
}
uint chiclet_keyboard_() //The key detection subroutine has a return value for exiting the subroutine
{
uchar dsa[10]; //Array for storing display
while(1) //Detection infinite loop until a key is detected or the time is up sec=0;
{
if(S1==0)
{
delay(5);
if(S1==0)
{
LCD_disp_cher(0,1," S1 "); //Display the key pressed first
return 0;
}
}
if(S2==0)
{
delay(5);
if(S2==0)
{
LCD_disp_cher(0,1," S2 "); //Display the key pressed first
return 0;
}
}
if(S3==0)
{
delay(5);
if(S3==0)
{
LCD_disp_cher(0,1," S3 "); //Display the key pressed first
return 0;
}
}
if(S4==0)
{
delay(5);
if(S4==0)
{
LCD_disp_cher(0,1," S4 "); //Display the key pressed first
return 0;
}
}
if(sec==0)
{
LCD_disp_cher(0,1," over time ");
return 0;
}
sprintf(dsa," time %d ",sec); //Display time
LCD_disp_cher(0,1,dsa);
}
}
#endif
Previous article:MCU + 1602 LCD digital clock program
Next article:Compile HEX microcontroller files using c51 command line
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- ADI's LT8645SIV#PBF chip uses the EN pin to control power on and off, causing it to burn out. Help~
- Problems with STM32F103C8T6 shutdown mode
- New typec interface M2 solid state drive box board 3 yuan a piece 10 pieces free shipping
- Real-time video processing set-top box.rar
- Three simple steps to operate the msp430 serial port interrupt
- 【Ufan Learning】How small is the Ufan learning board? ?
- [MicroPython] STM32 branch fixes a CDC problem when USB is reconnected
- Is Raspberry Pi considered open source hardware?
- How to debug with ST-Link in Embedded Studio for ARM?
- Comment to win a gift | TI SK-AM64 evaluation kit review