MICROPROCESSOR SYSTEMS ECSE 4790
Popular in Course
Popular in ELECTRICAL AND COMPUTER ENGINEERING
This 15 page Class Notes was uploaded by Miss Damien Crooks on Monday October 19, 2015. The Class Notes belongs to ECSE 4790 at Rensselaer Polytechnic Institute taught by Russell Kraft in Fall. Since its upload, it has received 55 views. For similar materials see /class/224768/ecse-4790-rensselaer-polytechnic-institute in ELECTRICAL AND COMPUTER ENGINEERING at Rensselaer Polytechnic Institute.
Reviews for MICROPROCESSOR SYSTEMS
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 10/19/15
IDE amp ANSI Display Lab Exercise Using the IDE and ANSI Display Commands Student s name amp ID 1 Partner s name amp ID 2 Your Section number amp 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 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 VT 100 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 10 with the 8051 PREPARATION Review the 8051 hardware features 0 Review the C language stdio utilities 0 References C8051F12x 13xpdf 8051 C8051F12XReference Manual Ch 1 11 18 C8051F12x DKpdf C8051F12XDevelopmentKit User s Guide VT100ANSI ESCAPE SEQUENCES and Helloc sample program IDE SETUP 1 Connecting The Board See the C8051F1 2X Development Kit User s Guide for details on connecting the board and USB Debug Adapter httpwwwecserpieducoursesCStudioSilabsC8051F12xDKpdf 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 Helloc 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 CMPSfilesfilenamewsp To compile your project first verify that all of the code is correct Click on the Project menu and select AssembleCompile 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 BuildMake 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 Page 2 code to the development board Finally to execute your code on the C8051F120 click on the Debug menu and select Go ANSI PROGRAMMING TASKS FOR THE 8051 1 Introduction To The User Interface Input from the terminal keyboard and output to the terminal display can be done using the getchara and putchara functions Write a simple C program to run on the 8051 that outputs quotThe keyboard character is quot whenever you type a printable character where stands for that character Since you will be waiting for an indefinite number of characters to be typed use ltESCgt or A key combination where A ltControlgt to end the program Display this information at the top of the screen when the program starts 2 VT100AN SI Terminal Control Escape Sequences ProComm Plus and HyperTerminal use VT100ANSI terminal emulation by default By sending special codes to the terminal it is possible to clear the screen position the cursor set terminal colors and many other operations These codes are called escape sequences because the first character is the ltESCgt character or 1B in ASCII 033 octal A table is included at the end of this lab that contains some useful escape codes Modify the C program of Part 1 to display yellow characters on a blue background Center the program termination information on line 2 Display the keyboard response text on line 6 Change the color of the keyed in character to white leaving the rest of the characters in yellow Now for nonprinting characters have the program blink the output quotThe keyboard character XX is 39 not printable 39 quot and beep where XX are the hexadecimal digits of the nonprintable character include the underline on the terminal This line should appear at the line in the center of the screen e g line 12 if 24 lines are being displayed in the terminal window Also although the top message may overwrite the previous message each time a new key is hit the not printable message should be written on the line beneath the previous line When it writes on the last line of the screen the terminal should scroll just the lines on the lower half of the screen See the figure below of a terminal screen shot Note that scrolling only occurs when you output a n while on the bottom line of the display Moving the cursor to the bottom line and writing will only overwrite any text already there There are escape sequences that simplify these operations which you are expected to use as much as possible Unfortunately the PCs and PC cards in the Sun workstations do not have external speakers so headphones are needed to hear the beep and ProComm must be used instead of HyperTerminal The version of HyperTerminal used on the PCs does not seem to support the beep sound AG 2 Ctrl G or ASCII 39BEL NOTE If the terminal doesn t respond properly to escape sequences it may no longer be in an ANSI compatible mode Make sure the leftmost bottom parameter button in the HyperTerminal window is set to either VT100 or ANSI BBS and likewise for ProComm Plus Good programmer39s tip Design the program top down Then write the routines bottom up Write them one at a time and thoroughly test each one before integrating them This way you will have isolated any errors to the routine that you are currently writing Good programmers follow this method Page 3 Eta gm new thnns Data Innis minim new Bapid Eminent Dela scupt File Dala v smqu 39 Program termination information line 2 Overwritten printable character line Scroll area for nonprintable c arac ers blinking text Hasl 7 that Laganw EmdMade 52mm Explaiel DDSPWDl as ASEll ldiieclcannecl ams tamsmcawctsf lawn lHaw AN WEE Dvengd cams i Nal Dunne ed Tu In T 3 Part InputOutput Configure the 8051 to properly execute the following tasks 0 Set Port 2 to output port bits use a voltmeter or a TA provided 67LED module with series current limiting resistors to verify values You will first need to set the corresponding bits in the port39s data direction register PZMDOUT to a 1 for output and use the latch register P2 to write the bits for output See the C8051F120 manual pp 250251 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 PIMDIN amp PlMDOUT on pp 249250 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 P10 Port 1 are 1 Enable the crossbar XERO XBRl ampXBR2 C8051F120 manual pp 245247 2 Configure Pln n 7 7 0 to open drain P2n n 7 7 0 to pushepull Page 4 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 AD 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 33V of the C8051F120 board Also be sure the 5V supply is NOT connected to the 33V supply on the microcontroller It isn t critical but probably a little safer if the potentiometers on the AD Converter Input Module are connected to 33V and ground from the C8051F120 board rather than 5V Page 5 ANSI ESCAPE ltESCgtC text text Line Cursor Home ltESCgtH cursorto Cursor ltESCgtROW cursor at Position COLH Cursor Up ltESCgtNUMA mr rup cursor Cursor ltESCgtNUMC Save Cursor ltESCgt s u current to ltESCgt start row to current cursor ltESCgt current row current row to Erase Up ltESCgt row to top screen screen moves Screen Section ENDr SRT 3B ltEscgt an Mode Set ATR1 3B set ATRn may be any of the values 3B Standard Reset Attributes Values for Bright Red Attribute Dim Green Mode Set Underscore Yellow Blink Blue Reverse 35 Magenta Magenta Hidden 36 Cyan Cyan 1 1 D 0 not or statement Ex ltESCgtROW 10COL 20H would be quotO331020Hquot Page 6 Tahle11j neclanuncuan Remsmrs mm 113 Snecml Functmn Reumers Con rmed Adams V mucur tame 11 3 Spam Funcuun Rems els canunueuy Table 113 5mm Funamn Reglsleis canunuem Pig m Tame 113 SpeciaVFunmon Remsle Acununueu m ruerven m m a term may AN unnemeusF ociuunsa 581 p mm m xa ya on Us magnum i m on a Cmssbarcun m z m Ramaanewsammcxnsmmwwsmv 24mmmmmecxnmmey aczc vmnnmnny am a 3 mm m cxnammwzawsm my MK vs H mm ha cxnmrvzmmz m mimsnmm an ME gt5 mm m m xnsmmm ww 2141raubmrmmmecxns z SVMV 2m re Gamam m cxusmmm m39y Fig 11 Helloc 8051 Test program to demonstrate serial port IO This program writes a message on the console using the printf function and reads characters using the getchar function An ANSI escape sequence is used to clear the screen if 39239 is typed A 39139 repeats the message and the program responds to other input characters with an appropriate message Includes include ltC8051f120hgt include ltstdio hgt include quotputget hquot Global Constants define EXTCLK 22118400 define SYSCLK 49760000 External oscillator frequency define BAUDRATE 115200 Output of PLL der UART baud rate in in Hz ived from EXTCLK 94 s Function Prototypes void main void lt lt 00 PP an I PORTiINITvoid voi UART07INIT void MAIN Routine void mainvoid char choice Disable the watchdog timer PORTiINIT Initialize the Crossbar and GPIO YSCLKiINITU Initialize the oscillator UARTOiINIT Initialize UARTO SFRPAGE UARTOiPAGE Direct output to UARTO printfquot0332Jquot rase the screen and move the cursor to the home position printfquotTest of the printf functionnnquot while1 printf quotHello Worldnnrquot printfquot greetings from Russe l P Kraft nnnrquot printfquot1repeat 2clear 0quitnnrquot Menu of choices choicegetchar putchar choice select which option to run if choice 39039 n else ifchoice 39139 printfquotnnHere we go againnnrquot else ifchoi e 39239 clear the screen with ltESCgt2J printf quot0332Jquot else i inform the user how bright he is printfquotc is not a valid choicenrquotchoice printf quotA quot putcharchoice pri tfquot is not a valid choicennrquot Page 12 SYSCLKiInit Initialize the system clock to use a 221184MHz crystal as its clock source vo id svscmLIN IT vo id int i char SFRPAGEisAVE SFRPAGE Save Current SFR page SFRPAGE CONFIGiPAGE OSCXCN 0x67 Start external oscillator with 221184MHz crystal fori0 i lt 256 i Wait for the oscillator to start u whileOSCXCN amp 0x80 CLK EL 0x01 OSCICN 0x00 SFRPAGE CONFIGiPAGE PLLOCN 0x SFRPAGE LEGACYiPAGE FLSCL 0x10 SFRPAGE CONFIGiPAGE i fori i lt 256 i PLLOCN x02 whilePLLOCN amp 0x10 CLKSEL 0x02 SFRPAGE SFRPAGEisAVE Restore SFR page PORTiInit Configure the Crossbar and GPIO ports vo id PORTiINIT void char SFRPAGEisAVE SFRPAGE Save Current SFR page SFRPAGE CONFIGiPAGE XBRO 0x04 Enable UARTO XBRl 0x00 XBRZ 0x40 Enable Crossbar and weak pull up POMDOUT 0x01 Set TXO pin to push pull SFRPAGE SFRPAGEisAVE Restore SFR page UART7Init Configure the UARTO using Timerl for ltbaudrategt and B N l void UARTOiINITvoid char SFRPAGEisAVE SFRPAGE Save Current SFR page SFRPAGE UARTOiPAGE SCONO x50 Mode 1 8 bit UART enable RX ss39I39Ao 0x10 SMODO 1 SFRPAGE TIMEROliPAGE 0 F0 MO TMOD 0x20 Timerl Mode 2 8 bit reload H1 SYSCLKBAUDRATE16 Set Timerl reload value for baudrate Timerl High Byte CKCON Timerl uses SYSCLK as time b se 1 THl TR1 1 Start Timerl Page 13 SFRPAGE UARTOiPAGE 0 1 Indicate TXO ready SFRPAGE SFRPAGEisAVE Restore SFR page putgeth Title Microcontroller Development putchar amp getchar functions Auth Date Created 03252005 Date Last Modified 03252005 Description httpchaokhunkmitlacthkswichiteasyleasyli3html Target C8051F120 Tool Chain KEIL c51 amp SDCC putchar void putcharchar c whileTIO TIO0 SBUFO c getchar char getcharvoid putcharc echo to terminal return SBUFO Page 14 LED Display Board sv cl umf m m A lt3 ux um AD Convemr Input Vol39zge Boaxd Page 15