Docsity

ANSI Display Lab Exercise with C Programming on 8051 Microcontroller - Prof. Russell P. Kr, Study notes of Microprocessors

Toggle sidebar
bg1
MPS IDE & ANSI Display Lab Exercise
Using the IDE and ANSI Display Commands
Student's name & ID (1): ___________________________________________________
Partner's name & ID (2): ___________________________________________________
Your Section number & TA's name __________________________________________
Notes:
You must work on this assignment with your partner.
Hand in a printer copy of your software listings for the team.
Hand in a neat copy of your circuit schematics for the team.
These will be returned to you so that they may be used for reference.
------------------------------- do not write below this line -----------------------------
POINTS
(1) (2)
TA init.
Grade for performance verification (50% max.)
Grade for answers to TA's questions (20% max.)
Grade for documentation and appearance (30% max.)
TOTAL
Grader's signature: ___________________________________________
Date: ______________________________________________________
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download ANSI Display Lab Exercise with C Programming on 8051 Microcontroller - Prof. Russell P. Kr and more Study notes Microprocessors in PDF only on Docsity!

MPS IDE & ANSI Display Lab Exercise

Using the IDE and ANSI Display Commands

Student's name & ID (1): ___________________________________________________

Partner's name & ID (2): ___________________________________________________

Your Section number & TA's name __________________________________________

Notes:

You must work on this assignment with your partner.

Hand in a printer copy of your software listings for the team.

Hand in a neat copy of your circuit schematics for the team.

These will be returned to you so that they may be used for reference.

------------------------------- do not write below this line -----------------------------

POINTS

TA init.

Grade for performance verification (50% max.)

Grade for answers to TA's questions (20% max.)

Grade for documentation and appearance (30% max.)

TOTAL

Grader's signature: ___________________________________________

Date: ______________________________________________________

Using the IDE and Programming an ANSI Display

GOAL

By doing this lab assignment, you will learn:

1. Exercise the 8051 CPU registers and built-in hardware.

2. To use the VT100 Terminal Interface (with HyperTerminal or ProComm Plus) on the 8051.

3. To program an ANSI terminal display through a C program using the SDCC Compiler.

4. Perform basic I/O with the 8051.

PREPARATION

  • Review the 8051 hardware features.
  • Review the C language stdio utilities.
  • References: C8051F12x-13x.pdf 8051 C8051F12X Reference Manual, Ch. 1, 11, 18

C8051F12x-DK.pdf C8051F12X Development Kit User’s Guide

VT100/ANSI ESCAPE SEQUENCES and Hello.c sample program

IDE SETUP

1. Connecting The Board

See the C8051F12X Development Kit User’s Guide for details on connecting the board and USB Debug

Adapter (http://www.ecse.rpi.edu/courses/CStudio/Silabs/C8051F12x-DK.pdf).

2. Using The IDE

Start the SiLabs IDE by clicking on Silicon Laboratories on the Start Menu and choosing Silicon

Laboratories IDE. Next, create a new project to which C files can be added. To create a new project,

click on the Project menu and select New. This will create an empty project. Add a new C file to the

project by clicking on the Project menu and selecting Add Files to Project. Give your new file a name,

such as the Hello.c included in this lab. The file will now be part of the project, and can be compiled.

Save the project by clicking on Project and selecting Save Project. WARNING : The project must be

saved in a location whose path contains no folders with space characters in its name. It is suggested that

you use C:\MPSfiles\ filename.wsp.

To compile your project, first verify that all of the code is correct. Click on the Project menu and select

Assemble/Compile File. The window at the bottom of the IDE will alert you of any errors or warnings it

finds in your code. If there are errors, correct them first before moving on to the next step. If there are

warnings, you may or may not want to correct them, depending on the nature of the warning. Click on

the Project menu and select Build/Make Project. After successfully building your project, you will

want to upload it to the development board. Before doing this, you will need to configure the adapter

used to download the source code. To do this, click on the Options menu and select Connection

Options. Once the window opens, select the USB Debug Adapter and click OK. You are now ready to

download the code. To do this, click on the Debug menu, and select Connect. This will connect the IDE

to the development board through the USB Debug Adapter. Click on the Debug menu again, and select

Download Object File. Select the file you just compiled, and click Download. This will download the

3. Port Input/Output

Configure the 8051 to properly execute the following tasks:

  • Set Port 2 to output port bits (use a voltmeter or a TA provided 6-LED module with series current

limiting resistors to verify values). You will first need to set the corresponding bits in the port’s data

direction register (P2MDOUT) to a 1 for output and use the latch register (P2) to write the bits for

output. See the C8051F120 manual, pp. 250-251, for details.

  • Set Port 1 to input logic levels applied to port pins (use 0 V (ground) for a logic low and +5 V

through a 1 k resistor for a logic high). Again, you will first need to set the registers (P1MDIN &

P1MDOUT on pp. 249- 2 50) bits for input and read from the latch register (P1 on p. 249).

  • Continuously read in a value on a bit on input Port 1 and output the value to the corresponding bit on

Port 2, which has been connected to an LED. After wiring the LEDs to the correct output pins and

applying a voltage to the input pins, the minimum steps necessary to read in a voltage on pin P1.

(Port 1) are:

1. Enable the crossbar (XBR0, XBR1 & XBR2: C8051F120 manual, pp. 245-247).

2. Configure P 1 .n (n = 7 – 0) to open drain; P 2 .n (n = 7 – 0) to push-pull.

Program termination

information line 2

Overwritten printable

character line 6

Scroll area for

nonprintable

characters

(blinking text)

3. Read the 8-bit numerical value from P1 into a local variable.

4. Write the value to P2.

If a potentiometer (use the pot modules assigned to lab groups by the TA) whose end terminals

are between ground and +5 V with the wiper connected to the A/D input is used to give various

voltage readings, you should be able to confirm that voltages near 0 V yields a numerical value of

0, and +5 V yields values yields 1. Explain why this makes sense. Determine if the input uses a

Schmitt trigger (hysteresis) on voltage levels.

NOTE: Make sure you provide a common ground connection between the +5V of your external TTL

circuit and the +3.3V of the C8051F120 board. Also be sure the +5V supply is NOT connected to the

+3.3V supply on the microcontroller. It isn’t critical, but probably a little safer, if the potentiometers on

the A/D Converter Input Module are connected to +3.3V and ground from the C8051F120 board rather

than +5V.

⇒ ⇒ ⇒ ⇒ ⇒

⇒ ⇒ ⇒

//------------------------------------------------------------------------------------------------- // SYSCLK_Init //------------------------------------------------------------------------------------------------- // // Initialize the system clock to use a 22.1184MHz crystal as its clock source // void SYSCLK_INIT(void) { int i; char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = CONFIG_PAGE; OSCXCN = 0x67; // Start external oscillator with 22.1184MHz crystal for(i=0; i < 256; i++); // Wait for the oscillator to start up while(!(OSCXCN & 0x80)); CLKSEL = 0x01; OSCICN = 0x00; SFRPAGE = CONFIG_PAGE; PLL0CN = 0x04; SFRPAGE = LEGACY_PAGE; FLSCL = 0x10; SFRPAGE = CONFIG_PAGE; PLL0CN |= 0x01; PLL0DIV = 0x04; PLL0FLT = 0x01; PLL0MUL = 0x09; for(i=0; i < 256; i++); PLL0CN |= 0x02; while(!(PLL0CN & 0x10)); CLKSEL = 0x02; SFRPAGE = SFRPAGE_SAVE; // Restore SFR page } //------------------------------------------------------------------------------------------------- // PORT_Init //------------------------------------------------------------------------------------------------- // // Configure the Crossbar and GPIO ports // void PORT_INIT(void) { char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = CONFIG_PAGE; XBR0 = 0x04; // Enable UART XBR1 = 0x00; XBR2 = 0x40; // Enable Crossbar and weak pull-up P0MDOUT |= 0x01; // Set TX0 pin to push-pull SFRPAGE = SFRPAGE_SAVE; // Restore SFR page } //------------------------------------------------------------------------------------------------- // UART)_Init //------------------------------------------------------------------------------------------------- // // Configure the UART0 using Timer1, for and 8 - N- 1 // void UART0_INIT(void) { char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = UART0_PAGE; SCON0 = 0x50; // Mode 1, 8 - bit UART, enable RX SSTA0 = 0x10; // SMOD0 = 1 SFRPAGE = TIMER01_PAGE; TMOD &= ~0xF0; TMOD |= 0x20; // Timer1, Mode 2, 8 - bit reload TH1 = - (SYSCLK/BAUDRATE/16); // Set Timer1 reload value for baudrate -- Timer1 High Byte CKCON |= 0x10; // Timer1 uses SYSCLK as time base TL1 = TH1; TR1 = 1; // Start Timer

SFRPAGE = UART0_PAGE; TI0 = 1; // Indicate TX0 ready SFRPAGE = SFRPAGE_SAVE; // Restore SFR page }

// putget.h
// Title: Microcontroller Development: putchar() & getchar() functions.
// Author: Dan Burke
// Date Created: 03.25.
// Date Last Modified: 03.25.
// Description: http://chaokhun.kmitl.ac.th/~kswichit/easy1/easy1_3.html
// Target: C8051F
// Tool Chain: KEIL C51 & SDCC
// putchar()
void putchar(char c)
while(!TI0);
TI0=0;
SBUF0 = c;
// getchar()
char getchar(void)
char c;
while(!RI0);
RI0 =0;
c = SBUF0;
putchar(c); // echo to terminal
return SBUF0;