Transmitter Program
#include
#define uchar unsigned char
#define uint unsigned int
void delay(uint);
void SET_SYSTEM(void);
uchar KEY_scan(void);
void main()
{
uchar data i;
delay(100);
SET_SYSTEM();
while(1)
{
i=KEY_scan();
if(i)
{
TI=0;
SBUF=i;
while(!TI);
}
}
}
/*************************************************************************************/
void delay(uint t) /* Delay subroutine*/
{
uchar i;
while(t--)
{
for(i=0;i<125;i++) {}; /* 12 MHz crystal is about 1 ms */
}
}
/*****************************************************************************************/
uchar KEY_scan(void) /*Keyboard scanning program (stand-alone)*/
{
uchar data key;
P1=0xff;
key=P1;
if(key==0xff) return 0;
else
{
delay(10);
key=P1;
if(key==0xff) return 0;
else
{
switch(key)
{
case 0xfe: return 1;break;
case 0xfd: return 2;break;
case 0xfb: return 3;break;
case 0xf7: return 4;break;
case 0xef: return 5;break;
case 0xdf: return 6;break;
case 0xbf: return 7;break;
case 0x7f: return 8;break;
default : return 9;
}
}
}
}
/***********************************************************************************/
void SET_SYSTEM(void)
{
TMOD=0x20; /* Timer 1 works in mode 2 */
PCON=PCON&0x07;
TH1=0xfe; /* Set the baud rate*/
TL1=0xfe;
SCON=0x50;
IE=0x00; /* That is, EA=0; turn off all interrupts*/
TI=0;
RI=0;
TR1=1;
}
/****************************************************************************************/
Receiver Program
#include
#define uchar unsigned char
#define uint unsigned int
void delay(uint);
void SET_SYSTEM(void);
uchar KEY_scan(void);
void LED_display(uchar ,uchar);
uchar xdata IO_8155_order _at_ 0x2100;
uchar xdata IO_8155_PA _at_ 0x2101;
uchar xdata IO_8155_PB _at_ 0x2102;
uchar xdata IO_8155_PC _at_ 0x2103;
uchar data dt=0;
uchar code dig_num[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; /*Segment selection code of common cathode digital tube */
void main()
{
delay(200);
SET_SYSTEM();
IO_8155_order=0x0d; /* 8155 initialization*/
while(1)
{
LED_display(0,dt);
P1=dt;
}
}
/***** ************************************************** ******************************/
void delay(uint t) /* Delay subroutine*/
{
uchar i;
while (t--)
{
for(i=0;i<125;i++) {}; /* 12 MHz crystal is about 1 ms */
}
}
/****************************************** **************************************************/
void LED_display (uchar d_bit,uchar digit) /* LED digital tube display subroutine*/
{ /*d_bit represents the bit selection code, digit represents the number to be displayed */
IO_8155_PC=d_bit; /* Bit selection code output */
IO_8155_PA=dig_num[ digit]; /* Segment selection code output */
delay(10);
}
/************************************ ************************************************** ***/
void SET_SYSTEM(void)
{
TMOD=0x20; /* Timer 1 works in mode 2 */
PCON=PCON&0x07;
TH1=0xfe; /* Set baud rate */
TL1=0xfe;
SCON=0x50;
IE=0x90; /* EA=1; ES=1; ET1=0; serial port interrupt is enabled, timer 1 interrupt is disabled*/
TI=0;
RI=0;
TR1=1;
}
/** ************************************************** *********************************/
void RI_RI(void) interrupt 4
{
RI=0;
dt=SBUF;
}
Previous article:LCD12864 Program
Next article:Traffic light program for 8051
- Popular Resources
- Popular amplifiers
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
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- EEWORLD University Hall - Five Lectures on Microwaves
- [Environmental Expert’s Smart Watch] Part 1: Long-awaited unboxing!
- [NXP Rapid IoT Review] Hello GPIO
- How to draw a plum blossom pad in AD? The plum blossom pad network is independent and does not belong to any network
- #idlemarket# Transfer a brand new STM32L433 development board
- Leakage current and withstand voltage test of single-cell lithium battery powered products
- Getting Started with I2C on MSP MCUs
- TMS320VC5509A and aic23b chip have problems collecting noise signal frequency
- TFT LCD display to set the timer
- Carbon Film Resistors Risks