Free Electronic Circuits & 8085 projects

Electronic projects with circuit diagram and 8085 microprocessor projects.

RS232 to TTl interface circuit through transistor

Published on Oct 26 2010 // Digital Circuits


PC's RS232 port to  control use of LED lights

AVR microcontroller serial procedures for the preparation of serial Atmega8 SCM frame structure with support for multiple data, there are three completely independent of the interrupt (reception completed, send the completed and transmit data register empty) and so on, which also supports multi-computer communication mode. This experiment is an example to introduce the Atmega8 AVR microcontroller programming serial port. Microcontroller using the serial port must be initialized before. Initialized as follows: 1. Serial receiver and transmitter that can be set: First, we needed to enable the receiver to the serial port or M8 transmitter, so I / O port (PD1: TXD, PD2: RXD) to work for the USART. 2. Serial port interrupt work settings: If you need to work on the serial port interrupt will have to set the USART interrupt required settings, if the work in the query, then the interrupt setting is unnecessary. This experiment is set to respond to the serial port to receive complete interrupt, that the receiver receives a complete frame, it will trigger a reception completion interrupt. 3. Baud rate settings: that is, set the serial data transfer rate to the normal communication between two serial ports to ensure that the baud rate must be the same. Set the baud rate of the 9600 experiment, the system clock source using the built 8MHZ, can look-up table (“Atmega8 Principles and Applications Handbook” page 129) are UBRR = 51. 4. Data frame setting: This study is set to 8 data bits + 1 stop bit. Therefore, this experiment the serial initialization procedure is as follows: void UART_init (void)

{

UCSRB = BIT (RXCIE) | BIT (RXEN) | BIT (TXEN); / / allow the serial port to send and receive and respond to the reception completion interrupt

UBRR = 51; / / set the serial baud rate is 9600

UCSRC = BIT (URSEL) | BIT (UCSZ1) | BIT (UCSZ0); / / 8-bit data frame +1 bits stop bits

} If you set the serial port on the AVR microcontroller is not too familiar with the case, the compiler can also use the ICC in the Application Wizard generates the serial port directly relevant code. Operation as follows: 1. Create a new file in the ICC; 2. Click the Application Builder Tools menu sub-menu will pop up the following screen, and then need to select the CPU for the M8, the crystal frequency is 8MHZ.

4. Click OK, the new file in just a complete code that is generated, in which the serial port initialization code is as follows: / / UART0 initialize

/ / Desired baud rate: 9600

/ / Actual: baud rate: 9615 (0.2%)

/ / Char size: 8 bit

/ / Parity: Disabled

void uart0_init (void)

{

UCSRB = 0x00; / / disable while setting baud rate

UCSRA = 0x00;

UCSRC = BIT (URSEL) | 0x06;

UBRRL = 0x33; / / set baud rate lo

UBRRH = 0x00; / / set baud rate hi

UCSRB = 0x98;

} We look at the code generated automatically using the ICC and our own code written in UCSRC, UBRR, UCSRB is not the same?

Communication protocol and command (2004-10-29) In order to ensure the normal PC, SCM and reliable communication, to avoid system malfunctions, we need to devise a simple communication protocol, but also the definition of understanding that allows PC and MCU command . Here we simply defined as follows: 1.PC sends the relay control instructions in a 4-character string of the format “s” S1S0 “p”, such as “s00p”. Where s and p character for the simple data validation, which means that when the microcontroller serial data received if the first one is the “s” is the fourth “p”, the microcontroller receives a valid command, or directive invalid. S1 is a single chip address recognition, if the microcontroller receives the address of S1 characters equal to their own code, the microcontroller executing the command, otherwise invalid. With this character we can through a PC serial port and multiple microcontrollers to communicate, set this communication we will elaborate later. S0 corresponds to the relay code, specify the relay pull or release if S0 = “a”, then the board all pull all the relays, if it is “b” is the full release. 2. Microcontrollers instruction back to the PC, also with four string format S2S1S0 “t”, such as “000t”. Where “t” to check code. Address code for the microcontroller S2, S1, S0 corresponding to the relay code. Return instruction for the PC, to determine whether the implementation of the SCM to issue instructions. S1S0 binary data, each state corresponds to a relay, said that if a relay for the release of 0 relays. 3. Communication testing. When the daemon starts, PC machine sends the “s00t” command, if the PC machine in less than 6 seconds to return the relay to receive MCU state (the state is to read the control relay I / O port level obtained ), the PC-judge communication is normal, normal use, otherwise the PC serial port communication is not normal machine tips. Since then, PC machine will automatically request every 5 seconds, a relay state, and after the operation buttons on the relay, panel PC, will take the initiative to send a status word. 4. Software upgrade instructions. When you need to upgrade the microcontroller software, PC sends commands to the microcontroller to enter BOOT load the program area, ready to update the software version. The instruction format for the “su” S0 “p”, S0 address code for the microcontroller. When the device enters BOOT zone, the PC sends S0 “upd” command, S0 address code for the microcontroller, PC, software upgrade notification is ready. PC, then close the serial port, open the ISP you are prompted to download the software upgrade. 5. Microcontroller reset command. When the MCU after the upgrade is completed online, PC machine can send the reset command to reset the microcontroller to re-enter the application area. Atmega8 the IAP application will be explained later. Describes the background and the use of PC program daemon written using VB6.0, which controls use of VB’s complete PC and SCM MSComm communication. Interface is as follows: 4. Click OK, the new file in just a complete code that is generated, in which the serial port initialization code is as follows: / / UART0 initialize

/ / Desired baud rate: 9600

/ / Actual: baud rate: 9615 (0.2%)

/ / Char size: 8 bit

/ / Parity: Disabled

void uart0_init (void)

{

UCSRB = 0x00; / / disable while setting baud rate

UCSRA = 0x00;

UCSRC = BIT (URSEL) | 0x06;

UBRRL = 0x33; / / set baud rate lo

UBRRH = 0x00; / / set baud rate hi

UCSRB = 0x98;

} We look at the code generated automatically using the ICC and our own code written in UCSRC, UBRR, UCSRB is not the same?

Communication protocol and command (2004-10-29) In order to ensure the normal PC, SCM and reliable communication, to avoid system malfunctions, we need to devise a simple communication protocol, but also the definition of understanding that allows PC and MCU command . Here we simply defined as follows: 1.PC sends the relay control instructions in a 4-character string of the format “s” S1S0 “p”, such as “s00p”. Where s and p character for the simple data validation, which means that when the microcontroller serial data received if the first one is the “s” is the fourth “p”, the microcontroller receives a valid command, or directive invalid. S1 is a single chip address recognition, if the microcontroller receives the address of S1 characters equal to their own code, the microcontroller executing the command, otherwise invalid. With this character we can through a PC serial port and multiple microcontrollers to communicate, set this communication we will elaborate later. S0 corresponds to the relay code, specify the relay pull or release if S0 = “a”, then the board all pull all the relays, if it is “b” is the full release. 2. Microcontrollers instruction back to the PC, also with four string format S2S1S0 “t”, such as “000t”. Where “t” to check code. Address code for the microcontroller S2, S1, S0 corresponding to the relay code. Return instruction for the PC, to determine whether the implementation of the SCM to issue instructions. S1S0 binary data, each state corresponds to a relay, said that if a relay for the release of 0 relays. 3. Communication testing. When the daemon starts, PC machine sends the “s00t” command, if the PC machine in less than 6 seconds to return the relay to receive MCU state (the state is to read the control relay I / O port level obtained ), the PC-judge communication is normal, normal use, otherwise the PC serial port communication is not normal machine tips. Since then, PC machine will automatically request every 5 seconds, a relay state, and after the operation buttons on the relay, panel PC, will take the initiative to send a status word. 4. Software upgrade instructions. When you need to upgrade the microcontroller software, PC sends commands to the microcontroller to enter BOOT load the program area, ready to update the software version. The instruction format for the “su” S0 “p”, S0 address code for the microcontroller. When the device enters BOOT zone, the PC sends S0 “upd” command, S0 address code for the microcontroller, PC, software upgrade notification is ready. PC, then close the serial port, open the ISP you are prompted to download the software upgrade. 5. Microcontroller reset command. When the MCU after the upgrade is completed online, PC machine can send the reset command to reset the microcontroller to re-enter the application area. Atmega8 the IAP application will be explained later. Describes the background and the use of PC program daemon written using VB6.0, which controls use of VB’s complete PC and SCM MSComm communication. Interface as follows:

Interface, every little button control panel for each experimental LED and relay. If serial communication is normal, then click on the experiment corresponding LED will light up the board relay, and then click, LED has been closed relay released. The full board by the control experiments all of the LED and the relay on or off. The following PC commands sent box is displayed for each PC, a control command, and return the results box will display the returned results of the implementation experiment board. The bottom button is the implementation of software upgrades online upgrade control test board. If you need to SCM software upgrade, no need here to download the program by using the ISP. Click the software upgrade, the microcontroller will return to obtain upgrade instructions to upgrade the prepared after the command, the program will automatically turn off the serial port, and then prompt you to download software to download using the SL process. When the software after upgrading, CPU is not automatically enter the application area, which is that you can reset the device or click Reset button front entry to automatically reset CUP application area. Practical application in the practical application of this experiment, the increase of the relay control circuit and the keyboard circuit. Either through the PC, can also be used to control the keys to control electrical switches lines: