Current location - Education and Training Encyclopedia - Graduation thesis - Understand the progress of 80C5 1 single chip microcomputer ~
Understand the progress of 80C5 1 single chip microcomputer ~
Stick two LCD 1602 drivers that I used (there are both buses and IO ports, which will definitely come in handy).

Then paste the driver on ADC0809 bus, but I don't know how to display the specific requirements of the landlord on LCD, so I can only save it in the array.

The hardware connection has been basically completed in the code, so I don't need to say anything else. ! ^_^

*********************************************************************

/*===========================================================================

KS0070(44780) 16x2 LCD drives the demonstration bus.

=============================================================================

Wiring diagram: LCM-51LCM-51LCM-51LCM-510.

DB0 - P0.0 DB4 - P0.4 RW - P2.0

db 1-p 0. 1 DB5-p 0.5 RC-p 2. 1

DB2-p 0.2 DB6-p 0.6 E-p 2.7 = & gt; 74ls00+wr+rd

Db3-p0.3db7-p0.7vlcd connects the 1K2 resistor to GND.

[Note]: The crystal frequency of AT89C5 1 is 12MHz.

============================================================================*/

//#pragma src // Generate an assembly file

# include & ltreg 5 1 . h & gt;

# include & ltintrins.h & gt

//= = = = = Macro definition of variable type identification, which everyone likes to do = = = = = = = = = =

# Define Uchar unsigned characters

# Define Uint unsigned integer

//= = = = = = = = = = LCM1602a port address definition = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

char xdata LCD 1602 cmd port _ at _ 0x 7 CFF; //E= 1 RS=0 RW=0

char xdata LCD 1602 wdata port _ at _ 0x 7 eff; //E = 1 RS= 1 RW=0

char xdata LCD 1602 status port _ at _ 0x 7 dff; //CS= 1 RS=0 RW= 1

# Define busy 0x80 // busy discrimination bit

For example, the code charexample [] = ". -Author Xiao Qi \ n ";;

Void Delay400Ms (invalid);

void delay 5 ms(void);

void LcdWriteData(char dataW);

void LcdWriteCommand( Uchar CMD,Uchar AttribC);

void LcdReset(void);

Invalid display (uchardd);

void DispOneChar(Uchar x,Uchar y,Uchar Wdata);

void ePutstr(Uchar x,Uchar y,Uchar code * ptr);

/= = = = = = = = = = = = Write a few words about the test main program = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Invalid master (invalid)

{

Uchar temperature;

delay 400 ms(); //Necessary delay when starting, waiting for lcm to enter the working state.

LcdReset(); //This is also necessary ... initialization.

temp = 32

ePutstr(0,0,exampl); //The upper line shows the predetermined character string.

delay 400 ms(); //Keep the display content.

delay 400 ms();

delay 400 ms();

delay 400 ms();

delay 400 ms();

delay 400 ms();

delay 400 ms();

delay 400 ms();

while( 1)

{

Temperature and humidity. = 0x7f// Only ASCII characters are displayed.

if(temp & lt; 32)temp = 32; //Mask the control characters and don't show them.

Display (temp++);

delay 400 ms();

}

}

/*=======================================================

Display string

=======================================================*/

void ePutstr(Uchar x,Uchar y,Uchar code *ptr) {

Uchar i,l = 0;

while (ptr[l]>3 1){ l++; };

for(I = 0; I & ltl;; i++) {

DispOneChar(x++,y,ptr[I]);

if ( x == 16 ){

x = 0; y ^= 1;

}

}

}

/*=======================================================

Demonstrate a continuous string and cooperate with the upper program to demonstrate the moving string.

=======================================================*/

Invalid display (Uchar dd) {

Ucal I;

for(I = 0; I< 16; i++) {

DispOneChar(i, 1,dd++);

dd & amp= 0x7f

if(DD & lt; 32)DD = 32;

}

}

/*=======================================================

Display cursor position

=======================================================*/

void LocateXY( char posx,char posy) {

Uchar temperature;

temp = posx & amp0xf

Posey & = 0x1;

if(posy)temp | = 0x 40;

temp | = 0x80

LcdWriteCommand(temp,0);

}

/*=======================================================

Displays characters at the specified position.

=======================================================*/

void DispOneChar(Uchar x,Uchar y,Uchar Wdata) {

LocateXY( x,y); //Locate the display address

LcdWriteData(Wdata); //Write characters

}

/*=======================================================

The initialization procedure must follow the initialization procedure described in the product data.

=======================================================*/

void LcdReset( void ) {

LcdWriteCommand( 0x38,0); //Display mode setting (no busy signal detected)

delay 5 ms();

LcdWriteCommand( 0x38,0); //* * * three times

delay 5 ms();

LcdWriteCommand( 0x38,0);

delay 5 ms();

LcdWriteCommand( 0x38, 1); //Display mode setting (detect future busy signal)

LcdWriteCommand( 0x08, 1); //Display off

LcdWriteCommand( 0x0 1, 1); //Display a clear screen

LcdWriteCommand( 0x06, 1); //Display cursor movement settings

LcdWriteCommand( 0x0c, 1); //Display and cursor settings

}

/*=======================================================

Write control character subroutine: E= 1 RS=0 RW=0.

=======================================================*/

void LcdWriteCommand( Uchar CMD,Uchar attributec){

if(AttribC)while(LCD 1602 status port & amp; Busy); //Detected a busy signal?

LCD 1602 CMD port = CMD;

}

/*=======================================================

Write a character subroutine at the current position: E = 1 RS= 1 RW=0.

=======================================================*/

void LcdWriteData( char dataW ) {

while(LCD 1602 status port & amp; Busy); //detect busy signal

LCD 1602 wdata port = dataW;

}

//Short delay

Invalid delay 5 ms (invalid)

{

Uint i = 5552

while(I-);

}

//Long delay

Invalid delay 400 milliseconds (invalid)

{

uchar I = 5;

uint j;

When (I-)

{

j = 7269

while(j-);

};

}

*********************************************************************

/*===================================================================

KS0070(44780) 16x2 LCD driver demo program Xiaoqi

=====================================================================

Wiring diagram: LCM-51LCM-51LCM-51LCM-510.

DB0 - P0.0 DB4 - P0.4 RS - P2.5

db 1-p 0. 1 DB5-p 0.5 RW-p 2.6

DB2 - P0.2 DB6 - P0.6 E - P2.7

Db3-p0.3db7-p0.7vlcd connects the 1K2 resistor to GND.

[Note]: The crystal frequency of AT89C5 1 is 12MHz.

====================================================================*/

# include & ltreg 5 1 . h & gt;

# include & ltintrins.h & gt

//Macro definition of variable type identification, which everyone likes to do.

# Define Uchar unsigned characters

# Define Uint unsigned integer

//Control pin definition, different connections must be modified.

sbit RS = p2^5;

sbit rw = p2^6;

sbit elcm = p2^7;

# Define data port P0 // Data port, and the resistor must be pulled high.

# Define Busy 0x80

For example, the code charexample [] = ". -Author Xiao Qi \ n ";;

Void Delay400Ms (invalid);

void delay 5 ms(void);

void WaitForEnable(void);

void LcdWriteData(char dataW);

void LcdWriteCommand( Uchar CMD,Uchar AttribC);

void LcdReset(void);

Invalid display (uchardd);

void DispOneChar(Uchar x,Uchar y,Uchar Wdata);

void ePutstr(Uchar x,Uchar y,Uchar code * ptr);

//Test the main program

Invalid master (invalid)

{

Uchar temperature;

delay 400 ms();

LcdReset();

temp = 32

ePutstr(0,0,exampl); //The upper line shows the predetermined character string.

delay 400 ms();

delay 400 ms();

delay 400 ms();

delay 400 ms();

delay 400 ms();

delay 400 ms();

delay 400 ms();

delay 400 ms();

while( 1)

{

Temperature and humidity. = 0x7f// Only ASCII characters are displayed.

if(temp & lt; 32)temp = 32; //Mask the control characters and don't show them.

Display (temp++);

delay 400 ms();

}

}

/*=======================================================

Display string

=======================================================*/

void ePutstr(Uchar x,Uchar y,Uchar code *ptr) {

Uchar i,l = 0;

while (ptr[l]>3 1){ l++; };

for(I = 0; I & ltl;; i++) {

DispOneChar(x++,y,ptr[I]);

if ( x == 16 ){

x = 0; y ^= 1;

}

}

}

/*=======================================================

Demonstrate a continuous string and cooperate with the upper program to demonstrate the moving string.

=======================================================*/

Invalid display (Uchar dd) {

Ucal I;

for(I = 0; I< 16; i++) {

DispOneChar(i, 1,dd++);

dd & amp= 0x7f

if(DD & lt; 32)DD = 32;

}

}

/*=======================================================

Display cursor position

=======================================================*/

void LocateXY( char posx,char posy) {

Uchar temperature;

temp = posx & amp0xf

Posey & = 0x1;

if(posy)temp | = 0x 40;

temp | = 0x80

LcdWriteCommand(temp,0);

}

/*=======================================================

Displays characters at the specified position.

=======================================================*/

void DispOneChar(Uchar x,Uchar y,Uchar Wdata) {

LocateXY( x,y); //Locate the display address

LcdWriteData(Wdata); //Write characters

}

/*=======================================================

The initialization procedure must follow the initialization procedure described in the product data.

=======================================================*/

void LcdReset( void ) {

LcdWriteCommand( 0x38,0); //Display mode setting (no busy signal detected)

delay 5 ms();

LcdWriteCommand( 0x38,0); //* * * three times

delay 5 ms();

LcdWriteCommand( 0x38,0);

delay 5 ms();

LcdWriteCommand( 0x38, 1); //Display mode setting (detect future busy signal)

LcdWriteCommand( 0x08, 1); //Display off

LcdWriteCommand( 0x0 1, 1); //Display a clear screen

LcdWriteCommand( 0x06, 1); //Display cursor movement settings

LcdWriteCommand( 0x0c, 1); //Display and cursor settings

}

/*=======================================================

Write control character subroutine: E= 1 RS=0 RW=0.

=======================================================*/

void LcdWriteCommand( Uchar CMD,Uchar attributec){

if(AttribC)WaitForEnable(); //Detected a busy signal?

RS = 0; RW = 0; _ nop _();

DataPort = CMD_ nop _(); //Send control word subroutine

elcm = 1; _ nop _(); _ nop _(); elcm = 0; //Run enable pulse signal

}

/*=======================================================

Write a character subroutine at the current position: E = 1 RS= 1 RW=0.

=======================================================*/

void LcdWriteData( char dataW ) {

WaitForEnable(); //detect busy signal

RS = 1; RW = 0; _ nop _();

DataPort = dataW_ nop _();

elcm = 1; _ nop _(); _ nop _(); elcm = 0; //Run enable pulse signal

}

/*=======================================================

The state of LCD controller must be checked before normal reading and writing operation: CS= 1 RS=0 RW= 1.

DB7: 0 LCD controller is idle; 1 LCD controller busy

========================================================*/

void WaitForEnable( void ) {

Data port = 0xff

RS = 0; RW = 1; _ nop _(); elcm = 1; _ nop _(); _ nop _();

And (data port & busy);

elcm = 0;

}

//Short delay

Invalid delay 5 ms (invalid)

{

Uint i = 5552

while(I-);

}

//Long delay

Invalid delay 400 milliseconds (invalid)

{

uchar I = 5;

uint j;

When (I-)

{

j = 7269

while(j-);

};

}

*********************************************************************

# include & ltREG5 1。 H & gt

# include & ltABSACC。 H & gt

# Define uchar unsigned characters

//Channel number, which varies according to actual hardware.

# defined in 0 XBYTE[0X0000] // channel 0.

# defined in 1 XBYTE[0X000 1]

# Define IN2 XBYTE[0X0002]

# defined in 3 XBYTE[0X0003]

# defined in 4 XBYTE[0X0004]

# defined in 5 XBYTE[0X0005]

# defined in 6 XBYTE[0X0006]

# defined in 7 XBYTE[0X0007]

sbit ad_busy=p3^5;

void ad 0809(uchar idata * x);

//After calling this program, analog quantity should be converted into digital quantity and stored in the array of adcRes[].

void AD0809(uchar idata *adcRes)

{

Ucal I;

data uchar xdata * ad _ adr

Ad _ ADR =&in0//points to the first channel.

for(I = 0; I<8; i++) {

* ad _ ADR = 0; //start AD conversion

ad _ busy = 0; //0 is found to be correct after debugging.

while(ad _ busy = = 0); //Wait for the AD conversion to end.

adcRes[I]= * ad _ ADR; //Save the conversion result

ad _ adr++; //Next channel

}

}