Simple 8051 Programming and Digital Design With VHDL
Simple 8051 Programming and Digital Design With VHDL
devices. Made for versatile capabilities, are found within a larger system thus the name embedded, like in phones, automobiles, washing machines etc. Integrated Circuits (IC) or chips are semiconductor wafer circuit packaging for deployed and implementation in electronics designs. A single chip could thousands or millions of transistors, resistors, capacitors or other electronics components and circuit designs. ICs could have digital or analogue functionalities on. Typical examples are amplifiers, logic gates (AND, OR, XOR etc), oscillators, timers, computers (microcontrollers and microprocessors) (CIO, 2012). 8051 microcontrollers are Harvard architecture based micro computer chips developed by Intel for embedded systems design (John, 1980). Has 8-bit CPU, I/O peripherals(32 bidirectional), program(64K) and data(64K) memories address spaces, [RAM(128 bytes), ROM (4 k-bytes)], counter/timers(two(2) 16 bit)], 6-source/5vector interrupt structure with two(2) priority levels and full duplex UART on a single chip (Intel, 1994). A design exercise with 8051 programming and hardware implementation is demonstrated in this assignment. VHDL is VHSIC (Very High Speed Integrated Circuit) Hardware Description Language would be used to design digital circuits in Altera Quartus II software.
Procedure and Results Question 1 A program which writes the last two (2) digits of a students Stamford ID into the 8051 microcontrollers internal RAM addresses from 40h to 6Fh with the same data. Assuming the last two (2) digits of ID as a decimal number and crystal oscillator is 11.0592MHz. Stamford students ID = 1119930 Last two(2) digits of my ID = 30 Program code: #include<reg51.h> unsigned int A; unsigned char *ptr; void main(void) { while(1) { ptr = 0x40; A = 30; for (ptr = 0x40; ptr <= 0x6f; ptr++) *ptr = A; } } // pointer address, RAM address 40h // Loads 30 into A // Loop to write 30 in the addresses 40h to 6Fh // loads data into pointer //Loop/Run continuously, until blocked //special function declaration to include/add 8051 header file // initializing the variable A // store a location in pointer, declare pointer // main has no return value
The result
The memory window showing that address 40h has 30 written in it.
The memory window showing that 30 has been written from address 40h to 6F Flow chart: to illustrate writing the last two (2) digits of a students Stamford ID into the 8051 microcontrollers internal RAM addresses from 40h to 6Fh with the same data. Last two (2) digits = 30, students ID = 1119930
Question 2 A program that counts down from the last four (4) digits of a students Stamford ID until zero. Once completed, the function will reset and countdown again. Assume the last two (2) digits of Stamford students ID is a decimal number and crystal oscillator is 11.0592MHz. Stamford students ID = 1119930 Last four (4) digits of my ID = 30 Program code: #include<reg51.h> header file unsigned int A = 9930; void main(void) { while (1) { for (A = 0; A <= 9930; A--) if (A == 0){ A = 9930; } } } // special function declaration to include/add 8051
// loop function to countdown from 9930 //check if countdown is complete //reset the variable to aid countdown, A=9930
The result:
The watch window showing the last four (4) digits of ID (9930) in variable counting continuously
Flow chart: to illustrate counting down from last four (4) digits of students Stamford ID in 8051 microcontroller. Last four (4) digits = 9930, students ID = 1119930
Question 3 VHDL Code for the function: F(x1, x2, x3) = m (0, 2, 4, 5, 6) The truth Table No. 0 1 2 3 4 5 6 7 X3 0 0 0 0 1 1 1 1 X2 0 0 1 1 0 0 1 1 X1 0 1 0 1 0 1 0 1 F (output) 1 0 1 0 1 1 1 0
Using Boolean algebra: F = + X2 + X1 + X1 X3 + X1 X2 (+ X2) + X1 ( +X3) + X1 (+ X2) (+ X2) + X1 ( +X3) + X1 (+ X2) + X1 + X1 (X1+)+ X1 X1 +
X2
inst1
inst
OR2 OUTPUT
NOT
X3
INPUT VCC
inst3
inst2
The VHDL code for the function X1 + generated with Quartus II.. LIBRARY ieee; USE ieee.std_logic_1164.all;
LIBRARY work;
ENTITY sss IS PORT ( x1 : IN STD_LOGIC; x2 : IN STD_LOGIC; x3 : IN STD_LOGIC; f : OUT STD_LOGIC ); END sss;
BEGIN SYNTHESIZED_WIRE_2 <= x1 AND SYNTHESIZED_WIRE_0; f <= SYNTHESIZED_WIRE_1 OR SYNTHESIZED_WIRE_2; SYNTHESIZED_WIRE_0 <= NOT(x2); SYNTHESIZED_WIRE_1 <= NOT(x3); END bdf_type;
Logic symbol for a 4-bit comparator (Floyd, Digital Fundamentals) Truth table for a 4-bit comparator Comparing Inputs A2, B2 A1, B1 A0, BO A>B X X X H X X X L A2 > B2 X X H A2 < B2 X X L A2 = B2 A1 > B1 X H A2 = B2 A1 < B1 X L A2 = B2 A1 = B1 A0>B0 H A2 = B2 A1 = B1 A0<B0 L A2 = B2 A1 = B1 A0=B0 H A2 = B2 A1 = B1 A0=B0 L A2 = B2 A1 = B1 A0=B0 L H = High, L = Low, X= Dont care. Outputs A<B L H L H L H L H L H L
A=B L L L L L L L L L L H
XNOR
a3
b3
inst
XNOR AND4
a2 b2
inst1
XNOR
OUTPUT
AeqB
a1
b1
inst4 inst2
XNOR
a0
b0
NOR2
OUTPUT
AltB
inst3
NOT
AND2
inst11
inst22 inst5
AND3 NOT
inst23
inst6
OR4 AND4 OUTPUT
NOT
AgtB
inst24
inst7
AND3
inst10
AND3 NOT
inst9
inst25
inst8
Block diagram schematic for a 4-bit comparator drawn with Quartus II software
10
Quartus II simulation vector waveform for a 4-bit comparator, with smaller period to capture more numbers.
VHDL Code for a 4-bit comparator: LIBRARY ieee; USE ieee.std_logic_1164.all; LIBRARY work; ENTITY Mysim4bitcomp IS PORT ( a3 : IN STD_LOGIC; b3 : IN STD_LOGIC; a2 : IN STD_LOGIC; b2 : IN STD_LOGIC; a1 : IN STD_LOGIC; b1 : IN STD_LOGIC; a0 : IN STD_LOGIC; b0 : IN STD_LOGIC; AeqB : OUT STD_LOGIC; AltB : OUT STD_LOGIC; AgtB : OUT STD_LOGIC ); END Mysim4bitcomp; ARCHITECTURE bdf_type OF Mysim4bitcomp IS SIGNAL SIGNAL SYNTHESIZED_WIRE_0 : STD_LOGIC; SYNTHESIZED_WIRE_1 : STD_LOGIC;
11
SIGNAL SIGNAL SIGNAL SIGNAL SIGNAL SIGNAL SIGNAL SIGNAL SIGNAL SIGNAL SIGNAL SIGNAL SIGNAL
SYNTHESIZED_WIRE_2 : STD_LOGIC; SYNTHESIZED_WIRE_3 : STD_LOGIC; SYNTHESIZED_WIRE_4 : STD_LOGIC; SYNTHESIZED_WIRE_5 : STD_LOGIC; SYNTHESIZED_WIRE_21 : STD_LOGIC; SYNTHESIZED_WIRE_22 : STD_LOGIC; SYNTHESIZED_WIRE_23 : STD_LOGIC; SYNTHESIZED_WIRE_9 : STD_LOGIC; SYNTHESIZED_WIRE_10 : STD_LOGIC; SYNTHESIZED_WIRE_12 : STD_LOGIC; SYNTHESIZED_WIRE_15 : STD_LOGIC; SYNTHESIZED_WIRE_17 : STD_LOGIC; SYNTHESIZED_WIRE_20 : STD_LOGIC;
BEGIN AeqB <= SYNTHESIZED_WIRE_5; AgtB <= SYNTHESIZED_WIRE_4; SYNTHESIZED_WIRE_21 <= NOT(a3 XOR b3); SYNTHESIZED_WIRE_22 <= NOT(a2 XOR b2); SYNTHESIZED_WIRE_4 <= SYNTHESIZED_WIRE_0 OR SYNTHESIZED_WIRE_1 OR SYNTHESIZED_WIRE_2 OR SYNTHESIZED_WIRE_3; AltB <= NOT(SYNTHESIZED_WIRE_4 OR SYNTHESIZED_WIRE_5); SYNTHESIZED_WIRE_23 <= NOT(a1 XOR b1); SYNTHESIZED_WIRE_10 <= NOT(b3); SYNTHESIZED_WIRE_12 <= NOT(b2); SYNTHESIZED_WIRE_15 <= NOT(b1); SYNTHESIZED_WIRE_17 <= NOT(b0); SYNTHESIZED_WIRE_9 <= NOT(a0 XOR b0); SYNTHESIZED_WIRE_5 <= SYNTHESIZED_WIRE_21 AND SYNTHESIZED_WIRE_22 AND SYNTHESIZED_WIRE_23 AND SYNTHESIZED_WIRE_9; SYNTHESIZED_WIRE_0 <= SYNTHESIZED_WIRE_10 AND a3;
12
SYNTHESIZED_WIRE_3 <= SYNTHESIZED_WIRE_21 AND SYNTHESIZED_WIRE_12 AND a2; SYNTHESIZED_WIRE_1 <= SYNTHESIZED_WIRE_22 AND SYNTHESIZED_WIRE_21 AND SYNTHESIZED_WIRE_15 AND a1; SYNTHESIZED_WIRE_20 <= SYNTHESIZED_WIRE_21 AND SYNTHESIZED_WIRE_17 AND a0; SYNTHESIZED_WIRE_2 <= SYNTHESIZED_WIRE_23 AND SYNTHESIZED_WIRE_22 AND SYNTHESIZED_WIRE_20; END bdf_type;
13
Discussion These questions are intended to make sense of the discussions relating to the basic principles and functions in defining specifications and providing solutions to engineering problems and innovations involving the use of embedded processors. It is pertinent that a basic understanding of the fundamentals of formalized hardware and software design process is established by way of analyzing and evaluating digital design using specialist software tools. This study is based on the 8051 microcontroller and Quartus II software. Embedded systems require coded instructions to perform certain desired tasks. Questions 1 and 2 are to basically demonstrate how to program the 8051 microcontroller and have the coded (program) function run the computer chip. C programming was used in both of the questions. Question 1 is about writing the last two (2) digits of a students Stamford ID in the addresses 40h to 6Fh. The ID used is 1119930, which makes the last two (2) digits 30 in this case. the flowchart of Loading ID = 30 in 8051 RAM Addresses 40h to 6Fh above helps in creating a visual flow of how the coding was done. An initialization of variables and header files was done as well as loading the variable A with 30. This variable is used in the program to store and duplicate the value to be written in the addresses specified while pointers was used in a for loop function to load the addresses. The code and a view of the memory window, showing 30 written at the addresses is as shown in question 1 part of the procedure and results above. A counting operation was performed in question 2. The last digits four (4) in this case is 9930 and it was required that a code is written to count down from this number, reset and countdown again continuously. A similar flow is used here a for loop is used to decrement the variable A which contains is originally loaded with 9930 and decrements until 0. A reset check is done by the line: if (A == 0){A = 9930; } after which the counting continues as long as the system is on. These two exercise can be downloaded into the UEL-51 Mk II kit for demonstration. A picture of UEL-51 Mk II is shown in the appendix. Digital design and VHDL coding was explored in questions 3 and 4. A three variable function was question was given question 3 which is HIGH at 0,2,4,5 and 6. A truth was made for the function before minimizing the function to reduce the number of gates used to save power consumed by the circuit, cost and space. K-mapping and Boolean algebra were used to check the simplification. The function was found to be X1+ after simplification. A circuit schematic was made in Quartus II from which the vector waveform and VHDL codes was generated and tallies with the truth table. The result is shown in the results for question 3. Comparators are used to check the equality of numbers. Using giving equal to, less than or greater than relationship between numbers. A bit-bit comparator means 4 bits can be compared. The procedure used to achieve the VHDL code for the comparator is similar to that of the function design in question 3. Since the comparator circuit was already provided it was drawn in Quartus II to generate the vector waveform and VHDL code which tallies with the truth table as shown in the results for question 4 above.
14
Summary Question 1 = program to write 30 into 8051 addresses 40h to 6Fh, c program coding, flowchat and results shown in the results above. Question 2 = program to continuously countdown from 9930 using c programming in 8051. Flowchart, coding and results shown. Questions 3 and 4 is about simulations to generate VHDL codes.
Conclusion That practice a very important component of learning makes this exercise has been very beneficial; it has enabled a demonstration of formalized process and tools used in developing digital design solutions. The 8051 microcontroller was programmed to perform addressing and counting, using specified digits of Stanford student ID numbers. Flowcharts, c program codes and well as the results obtained has been presented here. Digital design was performed in questions 3 and 4. The function in question 3 was minimized using k-map and also by Boolean algebra to reduce space circuit occupies, cost and power that would be consumed if left otherwise. While in question four (4) a 4-bit comparator which a setup that can show the equality, greater than and less than relationship between two 4-bit numbers. These were drawn in Quartus II and simulated to generate the respective vector waveforms and VHDL codes. With every task successfully completed, this experiment exercised has been studies and appreciated.
15
References CIO (2012) integrated circuit (IC) [online] available from: http://searchcio-midmarket.techtarget.com/definition/integrated-circuit [Accessed: April 2, 2012] Dr. A.J.ALKhalili, et al (2012) Design of a 4-bit comparator [online] Department of Electrical and Computer Engineering Concordia University Montreal, Quebec. Available from: http://users.encs.concordia.ca/~asim/COEN_6511/Projects/final6511report.pdf [Accessed: April 2, 2012] Engineers World (January 15, 2011) VHDL Code for 4 Bit Comparator [online]. Available from: http://engineersworld.wordpress.com/2011/01/15/vhdl-code-for-4-bit-comparator/ [March 23, 2012]. Intel (1994) MCS-51 Microcontroller Family Users Manual [online] Available from: http://eeweb1.poly.edu/networks/specs/27238302.pdf [Accessed April 1, 2012] John Wharton (1980) An Introduction to the Intel MCS-51TM Single-Chip Microcomputer Family. Intel Coporation. Lab Manual. (2012). Introduction to Quartus II, (EE3003) Embedded Systems and IC Design. Stamford College, PJ, Malaysia. Available in print [Accessed: April, 2012].
Thomas Floyd (2006). 9th edition. New Jersey: Person Education International.
16
Appendix
The UEL-51 MK II