#include
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
sbit CS1=P2^3;
sbit CS2=P2^4;
sbit RST=P2^5;
#define databus P0
#define uchar unsigned char
#define startline 0xc0
#define displayon 0x3f
#define startcolumn 0x40
#define page 0xb8
void init();
void clearscreen(uchar);
void readbusy();
void writecmd(uchar);
void writedata(vol);
//fly readdata();
void main()
{
flying i,j;
/*-- Text: Meng --*/
/*-- Songti 12; The corresponding dot matrix under this font is: width x height = 16x16 --*/
uchar code str[][16]={
0x00,0x10,0x10,0x10,0x11,0x11,0x91,0x11,0xF9,0x15,0x13,0x11,0x10,0x10,0x10,0x00,
0x40,0x40,0x40,0x7E,0x42,0x42,0x7E,0x43,0x42,0x7E,0x42,0x42,0x7E,0x40,0x40,0x00};
heat();
CS1=0;
CS2=1;
for(i=0;i<2;i++)
{
writecmd(i|page);
writecmd(startcolumn);
for(j=0;j<16;j++)
{
writedata(str[i][j]);
}
}
while(1);
}
void init()
{
RST=0;
RST=1;
CS1=0;
CS2=0;
writecmd(displayon);
writecmd(startline);
clearscreen(0);
}
void clearscreen(uchar select)
{
flying i,j;
switch(select)
{
case 0:CS1=0;CS2=0;break;
case 1:CS1=0;CS2=1;break;
case 2:CS1=1;CS2=0;break;
default:CS1=1;CS2=1;
}
for(i=0;i<8;i++)
{
writecmd(i|page);
writecmd(startcolumn);
for(j=0;j<64;j++)
{
writedata(0);
}
}
}
void readbusy()
{
RS=0;
RW=1;
do{
databus=0xff;
EN=1;
ACC=databus;
EN=0;
}while(ACC&0X80);
}
void writecmd(uchar cmd)
{
readbusy();
RS=0;
RW=0;
databus=cmd;
EN=1;
EN=0;
}
void writedata(uchar dat)
{
readbusy();
RS=1;
RW=0;
databus=that;
EN=1;
EN=0;
}
/*
fly readdata()
{
flying tempo;
readbusy();
RS=1;
RW=1;
databus=0xff;
EN=1;
temp=databus;
EN=0;
readbusy();
RS=1;
RW=1;
databus=0xff;
EN=1;
temp=databus;
EN=0;
return temp;
}
*/
Pay special attention to the busy read subroutine. If this is not handled properly, the screen will be completely black.
I have wasted a lot of time on this. The Keil c51 compiler supports the use of the accumulator ACC in C code.
This is very good. Because I have written an assembly driver for 12864 before, and it can run normally on both simulation and actual hardware.
But after switching to C language and trying to write them one by one, I got stuck on the use of ACC.
READBUSY: CLR RS
SETB RW
BUSY_0: MOV DATABUS,#0FFH; When P0 port is used as a general input port to read data, 1 should be written first.
SETB EN
MOV A,DATABUS
CLR EN; When reading data continuously, you don’t need to write 1.
JB ACC.7,BUSY_0
RIGHT
Because MOV A, DATABUS is not easy to translate directly into C, and now the C code written after using ACC is disassembled and the assembly code is
Same, and the drive is working fine.
Previous article:C51 non-blocking time-delayed water lamp
Next article:C51 Simple Electronic Clock
- Popular Resources
- Popular amplifiers
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- STM32CubeIDE imports the STM32 project automatically generated by Gizwits Online (based on the MDK environment
- Clear (set) CCS5.5 eclipse workspace record
- MSP430F5529 key interrupt scanning and pwm program
- FPGA_100 Days Journey_PS2 Design
- Are there any netizens who work in the motor industry?
- [ESP32-S2-Kaluga-1 Review] 5. Speech Synthesis Test
- Hello, I need help, but it's not urgent. How can I send an email using ESP8266?
- Saiyuan MCU baby bed remote control system
- There are five main types of display screens: LED, LCD, OLED, AMOLED, and TFT. Which screen is more suitable for which occasion?
- What sampling rate is required for an oscilloscope to measure signals without distortion?