Serial communication between C51 and atmega64 and PROTEUS simulation design

Publisher:幸福之舞Latest update time:2011-09-26 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Serial communication between C51 and atmega64. I won't go into details about the relevant theoretical knowledge here, but will just mention a few:

Several registers used by 51 UART

SCON:SM0 SM1 SM2 REN RB8 TX8 ONLY

PCON: SMOD --   --      --      ---    ---    PD IDLE

T2CON: TF2 EXF2  RCLK  TCLK  EXEN2  TR2  C/_T  CP/_RL2

TH2,TL2

Baud rate: 9600bps

avr:atmega64's two USARTs

Registers used

Uart0 is used here, so the relevant registers should be set during initialization:

UCSR0A : RXC TXC OUTPUT UPE U2X MPCM

UCSR0C :--  UMSEL UPM1 UPM0 USBS UCSZ1 UCSZ0 UCPOL

UBRR0H 、 UBRR0L、

UCSR0B :RXCIE TXCIE HITS RXEN TXEN UCSZ2 RXB8 TXB8

Don't ask me what these mean, if you don't understand, go look it up in a book.

Proteus simulation is as follows:

Serial communication UART and PROTEUS simulation - Moran 22 - Moran 22

The simulation results are shown in the figure below:

Serial communication UART and PROTEUS simulation - Moran 22 - Moran 22

It should be noted that:

Because I can only select 8MHz in the CKSEL Fuse of atmega64 in the simulation, the initialization baud rate in the AVR program is calculated based on 8MHz. So simulation is simulation, pay attention to the actual application.

When the 51 MCU uses timer 1 to generate the baud rate, it is said in the book that in mode 2, the maximum can only reach 4800bps at 12MHz. Here we have to use timer 2. But it is also very useful. . The 8052 core is used in the simulation. . Otherwise, don't blame me if there is no response. .

Finally, I attached the program. Some variables are declared but not used. It was just an experiment.

51's:

#include "reg52.h"

#define AA 0x61
#define commun_symbol 0x31
sbit LED=P2^0;
unsigned char Tx[]={"my name is seven!"};
void uart_init(void)
{
SCON   = 0x50;
RCAP2H = 0xFF;
RCAP2L = 0xD9;
TH2    = 0xFF;
TL2    = 0xD9;
T2CON  = 0x34;

}

void uart_send(unsigned char byData)
{
TI=0;
SBUF=byData;
while ( TI == 0 ) ;
TI=1;
} }

unsigned char uart_receive(void)
{
RI=0;
while(RI==0);
RI=1;
return(SBUF);
}

void main()
{
unsigned char byBuff,i;
uart_init();
uart_send(commun_symbol);
while(1)
{


byBuff=uart_receive();
LED=1;
if(byBuff==0x31)
{
for(i=0;i<20;i++)
{
P1=byBuff;
uart_send(Tx[i]);
}
}
}


}

Program for atmega64:

Two files, one is to modularize the function, and the other is the main function, calling (- -! Recently I have become accustomed to modularizing the program...)

//------------------uart.c---------------------

//----The communication function is modularized here------------

#include

void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x33; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x18;
}


void uart0_Transmit( unsigned char da ta )
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1< ;
/* Copy ninth bit to TXB8 */
UCSR0B &= ~(1< //if ( da ta & 0x0100 )
//UCSR0B |= (1< /* Put da ta into buffer, sends the da ta */
UDR0 = da ta;
}

unsigned char uart0_Receive( void )
{
/* Wait for receiving data*/
while ( !(UCSR0A & (1< ;
/* Get and return data from the buffer*/
return UDR0;
}

//--------------main.c-----------

//--------------------------------

#include
#include "spi.h"
#define commun_symbol 0x31

//-----------send a commun_symbol-----
//-----------receive a commun_symbol--
//      <--no,continue receive||||||yes-->receive the da ta and send
void main()
{
unsigned char bybuff;
DDRB=0xff;
PORTB=0xff;
uart0_init();
{

do
{
bybuff=uart0_Receive();
}
while (bybuff!=commun_symbol);//commun_symbol);
while(1)
{

uart0_Transmit(bybuff);
bybuff=uart0_Receive();
PORTB=(0xff|bybuff);
}
}
}

Reference address:Serial communication between C51 and atmega64 and PROTEUS simulation design

Previous article:Design of LED dot matrix display system based on STC89C55RD+ single chip microcomputer
Next article:Design of electronic password lock based on single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 15:33

Single chip microcomputer timer duty cycle button adjustment Proteus simulation program
The simulation schematic is as follows   The microcontroller source program is as follows: #include "reg52.h"  #define uchar unsigned char  #define uint unsigned int  float COUNT100,PWMCOUNT;  /*LCD port definition*/  sbit RS=P3^7;  sbit RW=P3^6;  sbit E=P3^5;  sbit PWM=P1^0;  sbit K1=P3^0; //add 1 sbit K2=P3^1; /
[Microcontroller]
Single chip microcomputer timer duty cycle button adjustment Proteus simulation program
UART Learning Notes
Serial port (UART) DIV_VAL = (PCLK / (bps x 16 ) ) −1 35 =  115200/66.5/16-1 View chip manual: GPACON  0x7F008000  R/W  Port A Configuration Register  0x0000 GPA0     0000 = Input   0001 = Output 0010 = UART RXD   0011 = Reserved 0100 = Reserved  0101 = Reserved
[Microcontroller]
MSP430F149 MCU implements uart data receiving interrupt
/******************************************************** Program function: MCU keeps sending data to PC and the corresponding           ASCII characters of 0~127 are displayed on the screen ------------------------------------------------------ Communication format: N.8.1, 9600 ---------------------------------------
[Microcontroller]
Proteus 20 application skills
Proteus 20 application skills are summarized by many loyal Proteus fans in their actual application process, so they are very practical! Today I will sort them out one by one to share with you. If there are better usage skills, everyone is welcome to share! ! F8: Show All Display the entire current workspace. F6:
[Microcontroller]
Proteus digital tube dynamic display problem solution
This article solves the problem of dynamic display of Proteus digital tube, the specific performance is as follows: The code used is: void display(void) {    P2=table ;    A1=0;A2=1;A3=0;A4=0;    delay(12); // A1=0;A2=0;A3=0;A4=0; //delay(1); P2=table &0xdf;//    A1=0;A2=0;A3=1;A4=0;    delay(12); // A1=0
[Microcontroller]
Proteus digital tube dynamic display problem solution
PIC microcontroller simulates asynchronous serial communication UART
Use TMR0 to implement timing query. It can be implemented on any PIC with interrupt. This method can be used to expand multiple serial ports. ;|--------------------------------------------------------------| ;| Implement duplex USART base on normal I/O pin | ;| Using TIMER0 interrupt for bit timing | ;| Tested on PIC
[Microcontroller]
PIC16F877A running light Proteus simulation program
The microcontroller source program is as follows: //Flowing lights #include pic.h //header file             __CONFIG(0xff32); //Configure fuse bits //Delay function void delay(unsigned int  x) {           unsigned int  i,j;     for(i=0;i x;i++)        for(j=0;j 100;j++); } //Main function void main()             
[Microcontroller]
PIC16F877A running light Proteus simulation program
Design of UART Interface Module Based on FPGA
UART (Universal Asynchronous Receiver Transmitter) is one of the widely used serial data transmission protocols, and its application range covers computer peripherals, industrial automation, etc. Although the USB transmission protocol has higher performance than the UART protocol, the circuit is complex and difficul
[Embedded]
Design of UART Interface Module Based on FPGA
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号