Showing posts with label embedded systems. Show all posts
Showing posts with label embedded systems. Show all posts

Simple Digital clock using 8051 microcontroller (AT89C51)


Simple Digital clock using 8051 microcontroller (AT89C51)
A digital clock is one that displays time digitally. The circuit explained here displays time with two ‘minutes’ digits and two ‘seconds’ digits on four seven segment displays. The seven segment and switches are interfaced with 8051 microcontroller AT89C51. This circuit can be used in cars, houses, offices etc.
DESCRIPTION :
As soon as the Vcc supply is provided to this circuit, the clock starts from 00:00. The time is displayed on four seven segments (in common anode configuration) by using the concept of multiplexing. This is achieved by using timer interrupt (Timer0) of AT89C51
which is configured to refresh seven segments. The segments are refreshed many times in a second for simultaneous display. The clock runs with a delay of exactly one second. Timer1 has been used to produce a time delay of one second. The data pins (a–h) of all the segments are interconnected and receive signal from port P2 of the microcontroller. The control or enable pins (common anode) are connected to pins 1-4 of port P1 (P1^0 – P1^3).
 The number on 4th segment (displaying the unit digit of second) is incremented once in a second as it goes from 0 to 9. The number on 3rd segment is incremented after every 10 seconds from 0 to 5. Thus seconds are displayed varying from 00 to 59. The digit on the 2nd segment changes after every 60 seconds (a minute) from 0 to 9 and so on. Thus the clock runs for an hour and after that it resets to zero again
CIRCUIT DIAGRAM :

VIDEOS :



READ MORE - Simple Digital clock using 8051 microcontroller (AT89C51)

How to interface computer's Serial Port (RS232) with 8051 microcontroller (AT89C51)


Several devices collect data from sensors and need to send it to another unit, like a computer, for further processing. Data transfer/communication is generally done in two ways: parallel and serial. In the parallel mode, data transfer is fast and uses more number of lines. This mode is good for short range data transfer.
Serial communication on the other hand, uses only one or two data lines to transfer data and is generally used for long distance communication. In serial communication the data is sent as one bit at a time. This article describes the interfacing of 8051 microcontroller (AT89C51) with a computer via serial port, RS232. Serial communication is commonly used in applications such as industrial automation systems, scientific analysis and certain consumer products
DESCRIPTION :
Serial Port
The microcontroller AT89C51 has an inbuilt UART for carrying out serial communication. The serial communication is done in the asynchronous mode. A serial port, like other PC ports, is a physical interface to establish data transfer between computer and an external hardware or device. This transfer, through serial port, takes place bit by bit.

IBM introduced the DB-9 RS-232 version of serial I/O standard, which is most widely used in PCs and several devices. In RS232, high and low bits are represented by flowing voltage ranges:
 
Bit
Voltage Range (in V)
0
+3
+25
1
-25
-3
 
The range -3V to +3V is undefined. The TTL standards came a long time after the RS232 standard was set. Due to this reason RS232 voltage levels are not compatible with TTL logic. Therefore, while connecting an RS232 to microcontroller system, a voltage converter is required. This converter converts the microcontroller output level to the RS232 voltage levels, and vice versa. IC MAX232, also known as line driver, is very commonly used for this purpose.
 
The simplest connection between a PC and microcontroller requires a minimum of three pins, RxD (receiver, pin2), TxD (transmitter, pin3) and ground (pin5) of the serial port of computer.  
 

TxD pin of serial port connects to RxD pin of controller via MAX232. And similarly, RxD pin of serial port connects to the TxD pin of controller through MAX232.
 
MAX232 has two sets of line drivers for transferring and receiving data. The line drivers used for transmission are called T1 and T2, where as the line drivers for receiver are designated as R1 and R2. The connection of MAX232 with computer and the controller is shown in the circuit diagram.
 
 
An important parameter considered while interfacing serial port is the Baud rate which is the speed at which data is transmitted serially. It is defined as number of bits transmitted or received per second. It is generally expressed in bps (bits per second). AT89C51 microcontroller can be set to transfer and receive serial data at different baud rates using software instructions. Timer1 is used to set the baud rate of serial communication for the microcontroller. For this purpose, Timer1 is used in mode2 which is an 8-bit auto reload mode. (Refer Timer programming with 8051) To get baud rates compatible with the PC, TH1 should be loaded with the values as shown:
 
Baud Rate (bps)                      TH1 (Hex value)
9600                                                FD
4800                                                FA
2400                                                F4
1200                                                E8

In this project baud rate 9600bps is used.
 For serial communication AT89C51 has registers SBUF and SCON (Serial control register). SBUF is an 8-bit register. For transmitting a data byte serially, it needs to be placed in the SBUF register. Similarly whenever a data byte is received serially, it comes in the SBUF register, i.e., SBUF register should be read to receive the serial byte.
SCON register is used to set the mode of serial communication. The project uses Mode1, in which the data length is of 8 bits and there is a start and a stop bit. The SCON register is bit addressable register. The following table shows the configuration of each bit. 

SCON (Serial Control) Register
SM0
SM1
SM2
REN
TB8
RB8
TI
RI
D7
D6
D5
D4
D3
D2
D1
D0
 
 
  SM0                SM1

    0                     0                    Serial mode 0
    0                     1                    Serial mode 1, 8-bit data, 1 start bit, 1 stop bit
    1                     0                    Serial mode 2
    1                     1                    Serial mode 3
 
 
TI (transmit interrupt) is an important flag bit in the SCON register. The controller raises the TI flag when the 8-bit character is transferred. This indicates that the next byte can be transferred now. The TI bit is raised at the beginning of the stop bit.
RI (receive interrupt) is also a flag bit of the SCON register. On receiving the serial data, the microcontroller skips the start and stop bits, and puts the byte is SBUF register. The RI flag bit is then raised to indicate that the byte has been received and should be picked up.
 
Hyper Terminal
Hyper Terminal, a Windows XP application, can be used to receive or transmit serial data through RS232. To open Hyper Terminal, go to Start Menu, select all programs, go to Accessories, click on Communications and select Hyper Terminal.
 
To start a new connection, go to File menu and click on new connection. The connection window opens up. Give a name to your connection and select 1sticon and click on OK. Connection property window opens here. Select Bit rate as 9600bps, Data bits 8, Parity as none, Stop bit 1, Flow control none and click OK. Now the serial data can be read on hyper terminal.

In program, Timer1 is used with auto reload setting. The baud rate is fixed to 9600bps by loading TH1 to 0xFD. The value 0x50 is loaded in the SCON register. This will initialize the serial port in Mode1. The program continuously receives a character (say ‘a’) from the serial port of the computer and transmits it back.

CIRCUIT DIAGRAM :
VIDEOS :


READ MORE - How to interface computer's Serial Port (RS232) with 8051 microcontroller (AT89C51)

software section of Micro C/OS-II kernel in ARM powered microcontroller


CHAPTER 7 
SOFTWARE SECTION
7.1. Keil IDE Software
        Keil IDE is a windows operating system (os) software program that runs on a PC to develop applications for ARM microcontroller and digital signal controller [7]. It is also called Integrated Development Environment or IDE because it provides a single integrated “environment” to develop code for embedded microcontroller. The rest of this briefly explains embedded system development and how Keil IDE is used.
         An embedded system is typically a design making use of the power of a small microcontroller, like a Phillips ARM. These microcontrollers combine a microprocessor unit(like the CPU in a desktop PC) with some additional circuits called “peripherals”, plus some additional circuits on the same chip to make a small control module requiring few other external devices. This single device can then be embedded into other electronic and mechanical device for low-cost digital control [7].
Keil software is the leading vendor for 8/16-bit development tools (ranked at first position in the 2004 embedded market study of the embedded system and EE times magazine).Keil software is represented worldwide in more than 40 countries, since the market introduction in 1988; the Keil C51 compiler is the de facto industry standard and supports more than 500 current 8051 device variants [7]. Now, Keil software offers development tools for ARM.
            Keil software makes C compilers, macro assemblers, real-time kernels, debuggers, simulators, integrated environments, and evaluation boards for 8051, 251, ARM and XC16x/C16x/ST10 microcontroller families.
An Example of using Keil uVision3 for creating Keil ARM’s Project:
1. Open Keil uVision Program which is Text Editor of Keil-ARM uses for writing C Language Source Code Program as inthe picture.
2.         Set default value to translate uVision3 Code to use withKeil uVision3 Program and Keil ARM.

 
There are 3 default values of them –Use Keil ARM ToolsUseGNU Tools, andUse ARM Tools- in this case, select “Use Keil ARM Tools then assign position of folder to savedefault value of Keil ARM Program. Generally, it is“C:\Keil\ARM\”, but if you install Keil in other position,you need to change correctly as in the picture.
3. Create new Project File. Click Project New Project then set the position of folder that you want to save with its title. For example, if you want to create Project File named LED_BLINK and save in folder named LED, you can set them by yourself [7]. After you fill its name in File name blank, click save project File as in the picture.
 
Program proceeding waits for users to set No. of MCU after you saved Project File. No.of Philips’MCU in ET-ARM STAMP LPC2119 Board is LPC2119 then click OK as in the picture Next, users need to confirm to copy File Startup of Keil to use with Philips’MCU or not because Startup File is the beginning value of MCU such as Stack values and default value to use with Phase-Lock-Loop. You should set values of them before starting to run your written program; otherwise MCU is added orders to run by the written program. Startup File of Keil-ARM is Assembly Language and is set to work with Keil Development. So, there are some different specifications to use. You can’t use Startup File with ET-ARM STAMP LPC2119 Board immediately; you need to change some default value. Using Keil ARM Program to translate orders, users need to correct Startup File to set value as well as ET-ARM STAMP LPC2119 Board form. In this case, select “No” to protect Keil uVision3 copy Startup File of Keil-ARM to use in this Project.
4. Copy File named ”Startup.s” that is in ETT’s CD-ROM in folder named “SOURCE_KEIL” into the same position of New Project File File named “Startup.S” which is contained orders of ARM7 in Assembly Language uses to set the necessary default value of MCU such as setting Stack value, Initial Phase-Lock-Loop, MAM Function, and MCU”s Vector. If you add “Startup.s File” from Keil or copy file from other source to use with “ET-ARM STAMP LPC2119 Board”, its program in Startup is different, and it will effect on written program [7]. 
5. Select Option of Project File. Click Project Option for target ‘target 1’ then select Tab of Target for setting MCU Target value. The proceeding is; X-TAL is 19.6608 MHz and set the MCU Memory is condition to translate Keil ARM Program as in the picture. 
6. Start to write Source Code with C Language by click File New… The Text File is displayed. In the first time, you should set its name as “Text1” as in the picture.
 
After finished to write program in C Language, you click save this file with its surname as”.C”. For example, File Save As… and then set its file name as “.main.c” as in the picture.
After saved file, colour of letters in this program is changed with its function such as Comment, Variable, and Order. It is the good point of Keil uVision3 program and users use it easily as in the picture.
7. Add File with Project File by click Project Components, Environment, Books[7]… then select Tab Project Components and then select Add File In the first time, you should select Files of type as “C Source files(*.c) because it shows other files name in Source Code. Click icon file named “main.c” then select Add file named “Startup.s” to Project File Set new File of type as “ASM Source files (*.s*;*.src;*.a*)”. Its file named Startup.s is shown in file name blank, click icon file “Startup.s”, and then select Add.
Fig 7.1: Output Screenshot of KEIL
8. Translate program by click Projects Rebuild all target files. Keil uVision3 Program can order Keil ARM Program to translate program immediately After translated program correctly without any mistake (0 Error and 0 Warning), you will get the HEX File name as same as the Project File name. Users can download HEX File to MCU immediately [7].
7.2. Flash Magic
Flash magic can control the entry into ISP mode of some microcontroller devices by using the COM port handshaking signals to control the device. Typically the handshaking signals are used to control such pins as Reset, PSEN and VCC. The exact pins used depend on the specific device. When this feature is supported, Flash Magic will automatically place the device into ISP mode at the beginning of an ISP operation.

 
Fig 7.2: Screenshot of Flash Magic

Flash Magic will then automatically cause the device to execute code at the end of the ISP operation.
CHAPTER-8
CONCLUSION AND FEATURE WORKS
 8.1 Conclusion
The system is thus designed and tested and found, thus the system is working properly. Proper set of instruction suitable for a specific application always lead to a better system
The science is a vast field and invention of new system is a part of it so still better systems. Can be invented and implemented with a bit of intelligence
8.2 Feature Works
 The most of the current kernels (RTOS) are successfully used in today’s real-time embedded systems, but they increase the cost and reduce flexibility.
Next generation real-time operating systems would demand new operating systems and task designs to support predictability, and high degree of adaptability. So our project can be further improve vise by utilization of upcoming new RTOS according to your application.
READ MORE - software section of Micro C/OS-II kernel in ARM powered microcontroller