Download - RTS Finalone

Transcript
  • 7/27/2019 RTS Finalone

    1/29

    1

    UNIVERSITY OF NOTTINGHAM

    SCHOOL OF ELECTRICAL AND ELECTRONIC

    ENGINEERING

    INTRODUCTION TO REAL-TIME SYSTEMS(H61RTS)

    TITLE: REPORT (LABS 5-9)

    Students name:Anant Johri

    Students ID:4042046

    PC Number: 18

    Name of Partner:Adam NealeSubmission date: 30/5/06

  • 7/27/2019 RTS Finalone

    2/29

    2

    INDEX

    1. Introduction..3

    2. Aims .4

    3. Task 15

    4. Task 28

    5. Task 3...11

    6. Task 4...12

    7. Conclusion...13

    8. Appendix.14

  • 7/27/2019 RTS Finalone

    3/29

    3

    Introduction

    The uses of DSPs in modern technology is increasing day by day so now there are of

    companies which manufacture DSPs for industrial use, some of these are designed for

    specific applications. The particular DSP used in this project is the Texas InstrumentsDSP Starter Kit, a basic DSP suitable for the programs and applications included in this

    particular project.

    Most of the work in the lab sessions was carried out on a DSK board, Vero board and on

    the software Code Composer Studio. Simple devices were built onto the Vero board

    and were controlled through the input and output ports of the DSK. The controlling of

    these devices were carried out through C code written on the software Code Composer

    Studio, running in real time with functions taking place on the board. The projects

    covered most of the input and output features of the DSK.

    One of the major parts of the project was to write proper C codes for operating the

    different devices on the vero-board and obtaining the desired results. Considerations

    particularly of calibration should be kept in mind while writing the code for controlling

    and interaction with devices on the Veroboard.

    In the following lab sessions the students revisited the concepts of the DAC (Digital to

    Analogue Converter) and timing events. The labs also introduced new interface

    techniques such as various kinds of Bit Manipulation (Bit masking, bit shifting etc) and

    also introduced Interrupts. The key feature of the session was familiarization with the

    hardware ensemble of the DSK which includes the keypad and the LCD (liquid crystal

    display).

    The concept of the ADC (Analogue to Digital Converter) was introduced. ADC converts

    analogue signals to digital ones. This technique is very helpful in the field of

    communication since transmission of digital data is faster, secure and also more noise

    resistant. All the concepts were applied and tested in a series of four tasks which

    culminated with the building of a Stand Alone Voltmeter.

  • 7/27/2019 RTS Finalone

    4/29

    4

    AIMS

    The aim of the session was the completion of the following tasks:-

    1. To modify the DAC into an ADC and to use it as a voltmeter.

    2. To interface with the Liquid Crystal Display

    Writing a message onto the screen

    Exploring some of the Character Control Instructions given in lab

    sheet.

    Making a timing diagram between the R/W, RS and E during a

    write operation.

    3. To interface with the Keypad

    By writing a code in the main routine

    By using an Interrupt

    4. To make a Stand Alone Voltmeter

  • 7/27/2019 RTS Finalone

    5/29

    5

    Task 1.Modify the DAC to become an ADC

    This task was mainly about to build an ADC using the DAC made in the lab sessions 3

    and 4 and then testing the ADC using a potentiometer. With use of a comparator, the

    output of the DAC (VDAC) could be coupled with another DC voltage (Vi) and a digital

    voltage would be seen at the output. The output from the DAC is connected to the

    inverting input of the comparator and DC voltage is connected to the non-inverting input

    of the comparator. The unknown voltage Vi is provided from the potentiometer. Also 5

    volt supply is also supplied to the comparator.

    The resistor at the output of the comparator is present to give a definite switch between

    logic low and logic high. When the output of the comparator is at logic high, the

    potential difference across the resistor will be very close to zero and the output voltage

    will be pulled up to 5V. While when the comparator output is at logic low, the potential

    difference across the resistor is high and so the output is kept at zero volts.

    Also known from the connections to the comparator are the values of inputs that will

    govern the logic state of the output, it is known that;

    If Vi > VDAC then Vout = 5v and,

    If Vi

  • 7/27/2019 RTS Finalone

    6/29

    6

    The table below shows how the successive approximation was carried out;

    MSB LSB

    Bit 0-7

    VDAC

    V0

    (128)

    V1

    (64)

    V2

    (32)

    V3

    (16)

    V4

    (8)

    V5

    (4)

    V6

    (2)

    V7

    (1)

    LM393

    Output

    Low 1 0 0 0 0 0 0 0

    High 0 1 0 0 0 0 0 0

    Low 0 1 1 0 0 0 0 0

    Low 0 1 0 1 0 0 0 0

    High 0 1 0 0 1 0 0 0

    Low 0 1 0 0 1 1 0 0

    Low 0 1 0 0 1 0 1 0

    Switchin

    g

    0 1 0 0 1 0 0 1

    The table shows how the successive approximation was carried out, setting the Most

    Significant Bit to one (logic high) first and monitoring the output of the comparator.

    By looking at the two statements that were known to be true for values of Vi &VDAC it

    was possible to see whether the value of VDAC needed to be increased or decreased. The

    high/low statements to the left of the table represent the output of the comparator, when it

    was low the value of VDAC had to be decreased and vice versa. At the value of VDAC that

    matched the value of Vi the scope displayed some switching between the two logic levels,

    this was because the voltages at the two inputs were very closely matched, any

    fluctuations in these voltages would result in a change in the output value.

  • 7/27/2019 RTS Finalone

    7/29

    7

    To ensure that the ADC was accurate it would have to be calibrated, the correct value of

    VDAC in the program would have to correspond to the correct value as the result of the

    successive approximation. In brackets in the top row of the table is the value that each

    significant bit of the DAC represents at the output, with the maximum value being 255

    when all bits are set to high. The conversion between these numbers and the value that

    they represent can be carried using the following formula;

    Sum of values set to logic 1 x 3.3 = VDAC255

    Where 255 is the Max. value of DAC mask and 3.3 is the Max. voltage of DAC

    So using this formula the value of VDAC can be found at any point, although it was only

    necessary to find the voltage at the end of the successive approximation and compare it to

    the measured value.

  • 7/27/2019 RTS Finalone

    8/29

    8

    Task 2. Interface with the LCD

    The LCD is an interface which consists of a series of digital inputs to the display and itdisplays characters given to it either via code or by the keypad. There are 14 differentpins on the LCD which are used for power supply, register selection, data bits etc. Three

    of these pins are

    (1). RS: This pin selects the register to be used, that is, it chooses between the dataregister and the input register and it is connected to bit 6 of *dpr0.(2). R/W: This pin mainly selects the working mode, that is, the reading mode or thewriting mode and it is connected to bit 7 of *dpr0.(3). E: This pin enables the signal to read or write and it is connected to bit 5 of *dpr0.

    The functions performed by the LCD depend on the combinations in which the pins gohigh. For example putting in the code *dpr1 = 0 x 01 would set the pins DB1-DB7 as lowand only DB0 would be high which is a signal to clear the screen and putting *dpr1=0x42

    or =B will display B on the screen.

    The main task involved in this section was to test the working of the display using thedisplay_test.out code and then programming the LCD to display a message, hold it forfive seconds, clear and reset the display, followed by another message.After that to testthe character control instructions described in the data sheet provided on the webpage andin the last to draw a timing diagram of the E, R/W and RS pin signals.

    For these tasks first of all the file display_test.out was run to test the display unit ofthe DSK. The result of running the file was that a message Ea2 is greatwas displayed onthe screen on the LCD proving that the display unit is working properly.

    For the second test a program (included in appendix) was written. The code started withdeclaring the header files and then declared all the global variables. The two memorymapped latches used were declared and initialized. The display was initialised, modesloaded, and the cursor was initiated. All these functions were carried out using thevarious display libraries and C routines provided. These functions are predefined in thedisplay_lib.c file and enable the basic LCD functions. The following header files hadto be included in the code to access the LCD;

    Init_display() -Initialises display.

    Load_modes() -Modes of operation of the LCD.

    Displayon_cursorblink() -Turns display on and makes cursor blink.

    Write_character(xxxx) -Writes character to display. A table of reference must be

    consulted to set the correct hexadecimal value of the

    character to be displayed. Can be converted to decimal.

  • 7/27/2019 RTS Finalone

    9/29

    9

    The function write_character() was used to write the character on the screen. Anargument, which is the character to be displayed, is passed to the function. There are twoways of passing an argument which include passing it as a hexadecimal code or withinquotes. For example the codes

    write_character(0x42);write_character(B);

    Both the above codes will display B on the LCD. The logic behind this is that the hexcodes represent the pins DB0 to DB7 of the LCD. The upper bit (4= 0100) represents thepins DB4 to DB7 and the lower bit of the hex code (2=0010) represents the pins DB0 toDB3.

    But the main problem in displaying the characters using the above statements is that onlyone character can be displayed at a time so if a long message is to be displayed then thismethod becomes quite tedious. So for overcoming this problem the array and loop can be

    used for long messages. One more limitation of the LCD was that it can display amaximum of 16 characters so if a very long message is to be displayed then only the last16 characters will be displayed. For example if the message hello guys! How are you?then only uys! How are you will be displayed on LCD.

    The second job involved in this task was to use some of the other character controlinstructions described in the datasheet. For this the display was shifted to the left afterdisplaying a message for sometime short time and then shifting that message to the leftand displaying the message following that. This was done by taking reference from thedata sheet, as shown in the datasheet in the instructions section the code forcursor/display movement is 0 0 0 1 S/C R/L 0 0 and for this condition S/C=0 and

    R/L is also 0. So code for this becomes 0 0 0 1 1 0 0 0 and decimal equivalent for thisis 18 so using *dpr1 = 0x18; in the code(given in the appendix) the display will beshifted to the left. This whole process of shifting was done in a subroutine calledmoveleft() so in the main this function was called after displaying some message andthis subroutine shifted the display to the left. Also different characters given in the figure12 of the datasheet was displayed on the LCD e.g

  • 7/27/2019 RTS Finalone

    10/29

    10

    The task also required a timing diagram between the signals at the E, R/W, RSduring a write operation. This was to be achieved using the oscilloscope. Three extra pinswere also added to the veroboard so as to enable connection with the oscilloscope. The

    following timing diagram was obtained.

  • 7/27/2019 RTS Finalone

    11/29

    11

    Task3-Interfacing the Keypad

    he keypad was based on a grid with 4 rows and 4 columns. For this task the keypad

    he process for identifying the pressed key was that the rows of the keypad were

    he above method would require the program to be activating and reading the inputs and

    un

    T

    need to be properly interfaced with the LCD so that messages could be displayed on the

    LCD as the keys are pressed. The connections of the keypad were in a grid so the basic

    operation was dependent on it. The data sheet provided on the webpage was really

    important as it provides all the knowledge about the connections and operations of the

    keypad. Also the lecture on keypad was really helpful as all things about keypad were

    told in that and due to this the students didnt face much problems during the lab

    sessions.

    T

    activated consecutively and then the logic state of the columns was monitored and in this

    way the pressed key can be located. The ASCII value of the pressed key is returned to the

    DSK and then transferred to an alphanumeric value. Using this method a program

    (included in appendix) was made, which reads the keypad once every second and prints

    the key pressed on the screen. In the program keypad.c each row was read and if the

    pressed key is present in it then the program displays it on the screen and after a short

    delay of 0.25sec it reads for another pressed key in the same procedure.

    T

    outputs of the keypad at all times, essentially waiting for a key to be pressed. This

    method of operation uses large amounts of CPU power that could be better employed

    elsewhere. Using interrupts in the program would mean that the program would only r

    when absolutely necessary, freeing up DSP resources. The interrupt would be used to

    trigger the scanning of the keypad. So another program keypad2.c which uses

    interrupts for the above purpose was made.

  • 7/27/2019 RTS Finalone

    12/29

    12

    Task4. Stand Alone Voltmeter

    his was the main task out of the four tasks as it requires all the knowledge which was

    he code started with the declaration of all the header files. All the variables and

    The code for this task was quite similar to the code used for the first task expect

    eypad.

    re equal

    che the working of the voltmeter a potentiometer was connected between the DAC

    t this point a few difficulties were faced. For instance the value of the voltage calculated

    value to an accuracy up to two decimal places.

    T

    applied in the last three tasks. The students were supposed to build a voltmeter that

    should work without getting any information from the computer. The voltage wasmeasured between pin0 and pin14 and then the output was displayed on the LCD screen.

    It was also to be triggered when a key is pressed on the keypad.

    T

    functions used were also declared and initiated. The input and output ports (input_latch

    and output_latch respectively) were also declared. In the main routine the display was

    initiated and loaded. Also all the interrupts were assigned pins and were enabled. The

    timer function was also declared.

    keypad_isr() interrupt service routine was used since it was to triggered by the k

    After making the required code, the voltage that is to be measured was given to the non-

    inverting input of the comparator. The DAC then starts supplying voltage to the

    comparator till the voltage is equal to the one being fed. When the two voltages a

    the comparator goes high. This voltage was then measured and displayed on the LCD. All

    this happens only after a key is pressed on the keypad (which triggers the ISR).

    To ck

    and the input (to provide a range of voltages). The program was built, loaded and run.

    The Code Composer was closed so as to disconnect the DSP from the computer. When a

    key was pressed on the keypad, the voltage supplied was displayed on the screen. Every

    time a button was pressed the current voltage being supplied was displayed.

    A

    was different than the value displayed (less accurate). To improve upon this the following

    code was used sprintf(ch,"%3.2f",var); which calculated and displayed the voltage

  • 7/27/2019 RTS Finalone

    13/29

    13

    Conclusion

    In the lab sessions the waves on the oscilloscope were created and DSK was used to readoltages. Also sources other then computer were used to read information. In the end, the

    SK was made to function alone without receiving any information from the computer.

    ultsan be obtained. The routing of inputs and outputs, voltage supplies and ground terminals

    ools such as scanf, printf, delays, timers etc before the writing each code so that

    e most efficient programs can be created.

    rograms that were not working first startedorking as soon as the DSK was turned off and restarted. The students also came to

    ry basic level, and as externalontrollers of machinery at the higher and industrial levels. The art of data analysis and

    OTE:-

    v

    DThe modification of DAC to become an ADC was also very interesting and learning.

    The different codes written during the lab sessions gave the students a goodunderstanding of how the software and hardware works together so that desired rescaround the board helped in understanding how all of the components and devices workedtogether.

    The module required that the students should establish the relevant knowledge of thesoftware t

    thMany difficulties arose during the labs sessions. One of them was that sometimes theDSKs behaved in a surprising way as the pwknow the limitations of LCD that it can display a maximum of 16 characters at a time soif a very long message is passed then only the last 16 characters would be displayed. Thedata sheets proved to be very useful when trying to overcome specific problems or whentrying to make the programs for efficient and work faster.

    So microprocessors are the building blocks of technology. They can be used as

    voltmeters, waveform generators and comparators at the vectransmission depends a lot on the power of the microprocessors used.

    N This report was supposed to be done by our group i.e. by me and my partnerdam Neale but he didnt turn-up for 4 lab sessions out of 5. So almost all the lab work

    e. Also he didnt help me in making this report so I made this whole reportAwas done by mby myself only .as he dint turn up and did not help in making this report i expect the markdistribution to be 100 % mark distribution Anant Johri and 0 % mark distribution Adam

    Neale.

  • 7/27/2019 RTS Finalone

    14/29

    14

    /* C code for task 1 */simple program to output a sine or triangle wave to the DAC */

    Group x 10/2002 */

    include "c6x11dsk.h"

    (int msec); /* declare the function which is coded after

    ternal o/p

    olatile unsigned int *input_latch = (unsigned int *) 0xA000000C;

    /

    t x, volts;

    x=1;;

    hile((x>0) && (volts

  • 7/27/2019 RTS Finalone

    15/29

    15

    /******************************************************************/FUNCTION : delay_microsec

    oduce a delay of x us during programecution

    ***********/microsec(int msec)

    mer_limit = (msec*75>>1); /*37.5 timer clock periods = 1 us*/

    /* set up Timer by writing control values to the timer control registers

    /* Hold the timer */

    Use CPU CLK - 37.5 MHz */t *)TIMER0_CTRL |= 0x200;

    _PRD = 2147483648;

    ed volatile int *)TIMER0_COUNT; /* read the present

    time_gone = 0; /* set initial value for time_gone */

    imer 0 until you reach the value reqd for the delay */

    {present

    e_gone = time_now - time_start; /* calculate how

    op */

    c() */

    **

    * DESCRIPTION :* uses the on board Timer 0 to prex***********************************************************void delay_{int timer_limit, time_start, time_gone, time_now; /* declare variables */

    ti

    */

    *(unsigned volatile int *)TIMER0_CTRL &= 0xff3f;/**(unsigned volatile in/* Set the max possible value for the 32 bit counter */*(unsigned volatile int *)TIMER0

    /* Start the timer */*(unsigned volatile int *)TIMER0_CTRL |= 0xC0;

    time_start = *(unsignvalue of timer0 */

    /* keep reading Twhile (time_gone < timer_limit)

    time_now = *(unsigned volatile int *)TIMER0_COUNT; /* read thevalue of timer0 */

    timlong we have waited */

    } /* end while lo} /* end delay_microse

  • 7/27/2019 RTS Finalone

    16/29

    16

    /***************************************/C code for Task 2 */

    display . C */

    include "c6711dsk.h"h"

    lib.h"

    ====/

    uts("program starting!\n");

    set up the display */

    ad_modes();;

    aded\n");

    rite_character('H');

    te_character('L');

    ;

    ter('L');

    );

    /*/*/* *//* C file to write message to LCD display */

    /* *//* *//**************************************/

    #include #include ##include "timer_lib.#include "display_/*

    * ======== main ====*void main(){p/*init_display();lodisplayon_cursorblink()

    puts("modes lo/*write a message*//*wwrite_character('E');wriwrite_character('L');write_character('O');delay_millisec(5000)moveleft();write_character('H');write_character('E');write_characwrite_character('L');write_character('O');write_character('H');write_character('E');write_character('L');write_character(0xC3write_character('L');

  • 7/27/2019 RTS Finalone

    17/29

    17

    write_character('O');write_character('H');write_character('E');write_character('L');write_character('L');

    write_character('O');write_character('J');write_character('K');write_character('L');write_character('M');

    /);

    ();

    rite_character('A');

    write_character('O');*//delay_millisec(5000//load_modes();//displayon_cursorblink

    while(1)

    {w}

    }

  • 7/27/2019 RTS Finalone

    18/29

    18

    *****************************************/

    C code for Task 2 */display_lib.C */

    oid busy();

    oid load_modes();_cursorblink();

    t my_char);

    olatile unsigned int *dpr0 = (unsigned int *) 0xA0000000; /* 1st external*/

    latile unsigned int *dpr1 = (unsigned int *) 0xA0000004;

    enable high (ie write an instruction)*/at least 200 ns !!*/

    ke enable low again */

    oid busy()

    gned int *dpr0 = (unsigned int *) 0xA0000000; /* 1st externalmory address */

    nsigned int *dpr1 = (unsigned int *) 0xA0000004; /* 2nd external

    dpr2 = (unsigned int *) 0xA0000008; /* 3rd external

    // repeat whilst busy flag (bit 7) is 1

    0; /* set input to display register = 0 */

    /*/*/*/* */

    /* C functions to drive the LCD display *//* *//* *//******************************************/

    #include "timer_lib.h"

    vvoid init_display();vvoid displayon

    void write_character(invoid moveleft();

    void moveleft(){vmemory addressvo*dpr0 = 0x0F; /* set reg select, r/W and enable low*/delay_millisec(15);*dpr1 = 0x18; /* set DL to high*/

    delay_millisec(1);*dpr0 = 0x20; /* setdelay_millisec(1); /* keep high for*dpr0 = 0x0F; /* ta}/* busy */v{int i, bu;volatile unsimevolatile umemory address */volatile unsigned int *memory ad */

    bu = 1;while (bu != 0){*dpr1 =

  • 7/27/2019 RTS Finalone

    19/29

    19

    delay_millisec(1);*dpr0 = 0x80; // r/w high

    timing is OKable high

    able lowo read only bit 0 */

    nt *dpr0 = (unsigned int *) 0xA0000000; /* 1st external

    latile unsigned int *dpr1 = (unsigned int *) 0xA0000004; /* 2nd external

    dpr1 = 0x30; /* set DL to high*/

    enable high (ie write an instruction)*/at least 200 ns !!*/

    ke enable low again */

    elay_millisec(1);t renable high (ie write an instruction)*/

    at least 200 ns !!*/ke enable low again*/

    elay_millisec(1);t renable high (ie write an instruction)*/

    at least 200 ns !!*/ke enable low again*/

    delay_millisec(1); // simple delay to ensure access*dpr0 = 0x20; // endelay_millisec(1);

    i = *dpr2; // read busydelay_millisec(1);*dpr0 = 0xDF; // enbu = i & 0x01; /* mask t}delay_millisec(1);} /* end of busy */

    /* initialisation */void init_display(){

    volatile unsigned imemory address */vomemory address */

    *dpr0 = 0x0F; /* set reg select, r/W and enable low*/delay_millisec(15);*delay_millisec(1);*dpr0 = 0x20; /* setdelay_millisec(1); /* keep high for

    *dpr0 = 0x0F; /* tadelay_millisec(5);*dpr1 = 0x30; /* set DL to high*/d*dpr0 = 0x20; /* sedelay_millisec(1); /* keep high for*dpr0 = 0x0F; /* tadelay_millisec(1);*dpr1 = 0x30; /* set DL to high*/d*dpr0 = 0x20; /* sedelay_millisec(1); /* keep high for*dpr0 = 0x0F; /* tadelay_millisec(1);} /* end of dislay_init() */

  • 7/27/2019 RTS Finalone

    20/29

    20

    /* function set */oid load_modes()

    int *dpr0 = (unsigned int *) 0xA0000000; /* 1st external

    latile unsigned int *dpr1 = (unsigned int *) 0xA0000004; /* 2nd external

    reg select, r/W and enable low*/elay_millisec(1);

    0x38; /* 8 bits, 2 lines 5x7 dots */

    t renable high (ie write an instruction)*/00 ns !!*/

    ke enable low again */

    able low*/

    0x08; /* display off */

    t renable high (ie write an instruction)*/for at least 200 ns !!*/

    ke enable low again */

    able low*/

    0x01; /* clear display, return cursor */

    t renable high (ie write an instruction)*/s !!*/

    ke enable low again */

    able low*/

    0x06; /* shift mode - entry mode set */

    t renable high (ie write an instruction)*/s !!*/

    ke enable low again */

    k */

    v{volatile unsignedmemory address */

    vomemory address */

    busy();*dpr0 = 0x0F; /* setd*dpr1 =delay_millisec(1);*dpr0 = 0x20; /* sedelay_millisec(1); /* keep high for at least 2*dpr0 = 0x0F; /* ta

    delay_millisec(1);busy();*dpr0 = 0x0F; /* set reg select, r/W and endelay_millisec(1);*dpr1 =delay_millisec(1);*dpr0 = 0x20; /* sedelay_millisec(1); /* keep high*dpr0 = 0x0F; /* tadelay_millisec(1);busy();

    *dpr0 = 0x0F; /* set reg select, r/W and endelay_millisec(1);*dpr1 =delay_millisec(1);*dpr0 = 0x20; /* sedelay_millisec(1); /* keep high for at least 200 n*dpr0 = 0x0F; /* tadelay_millisec(1);busy();*dpr0 = 0x0F; /* set reg select, r/W and endelay_millisec(1);*dpr1 =delay_millisec(1);*dpr0 = 0x20; /* sedelay_millisec(1); /* keep high for at least 200 n*dpr0 = 0x0F; /* ta} /* end load_modes */

    /* display on, cursor blin

  • 7/27/2019 RTS Finalone

    21/29

    21

    void displayon_cursorblink()

    olatile unsigned int *dpr0 = (unsigned int *) 0xA0000000; /* 1st external

    latile unsigned int *dpr1 = (unsigned int *) 0xA0000004; /* 2nd external

    reg select, r/W and enable low*/elay_millisec(1);

    0x0F; /* display on, cursor blink */

    t renable high (ie write an instruction)*/0 ns !!*/

    ke enable low again */

    module */d write_character(int my_char)

    nsigned int *) 0xA0000000; /* 1st external

    latile unsigned int *dpr1 = (unsigned int *) 0xA0000004; /* 2nd external

    reg select high, r/W and enable low*/elay_millisec(1);y_char; /* display my character */

    t renable high (ie write an instruction)*/0 ns !!*/

    ke enable low again */

    {vmemory address */vo

    memory address */

    busy();*dpr0 = 0x0F; /* setd*dpr1 =delay_millisec(1);*dpr0 = 0x20; /* sedelay_millisec(1); /* keep high for at least 20*dpr0 = 0x0F; /* tadelay_millisec(1);

    }

    /* write character tovoi{volatile unsigned int *dpr0 = (umemory address */vomemory address */

    busy();

    *dpr0 = 0x40; /* setd*dpr1 = mdelay_millisec(1);*dpr0 = 0x60; /* sedelay_millisec(1); /* keep high for at least 20*dpr0 = 0x0F; /* tadelay_millisec(1);

    }

  • 7/27/2019 RTS Finalone

    22/29

    22

    /****************************************/C code for Task 3 */

    eypad . C */

    include "c6711dsk.h"h"

    lib.h"

    =====*/

    main()

    ar ch;

    ile (1)

    ch = read_keypad_rowj(); /* read the first row only */c\n",ch);

    lay_millisec(250); /* 0.25 second delay before next read */

    */

    /

    /*/* k/* *//* Basic program to interrogate keypad */

    /* *//* *//***************************************/

    #include #include ##include "timer_lib.#include "keypad_

    /** ======== main ===void{chwh{

    printf("%de

    ch = read_keypad_rowk(); /* read the second row onlyprintf("%c\n",ch);delay_millisec(250); /* 0.25 second delay before next read */ch = read_keypad_rowl(); /* read the third row only */printf("%c\n",ch);delay_millisec(250); /* 0.25 second delay before next read */ch = read_keypad_rowm(); /* read the fourth row only *printf("%c\n",ch);delay_millisec(250); /* 0.25 second delay before next read */}

    }

  • 7/27/2019 RTS Finalone

    23/29

    23

    /***************************************/

    C code for Task 3 */keypad2 . C */

    include "c6711dsk.h"h"

    lib.h"

    ======== main ========*/

    main()

    t x;

    R = 0x100; /* global disable maskable interrupts */nterrupts disabled (global)!\n");

    */

    IER |= 0x0020; /* enable int 5 (external interrupt 5)*/!\n");

    hile (x == 0) /* while loop to keep main alive */

    /*/*/* */

    /* Basic program to interrogate keypad *//* *//* *//**************************************/

    #include #include ##include "timer_lib.#include "keypad_

    void keypad_isr();

    /*void{inCSputs("i

    IER = 2; /* disable all interrupts*/ICR = 0xffff; /* clear all pending interruptsputs("program is starting \n");

    puts("interrupt enabled (individual)CSR |= 0x1; /*global interrupt enable*/puts("interrupts enabled (global)!\n");

    x = 0;w{x=0;}}

  • 7/27/2019 RTS Finalone

    24/29

    24

    interrupt void keypad_isr()

    har ch;terrupts at the start of the ISR */

    5 activated \n"); /* interrupt task */

    only */rintf("%c\n",ch);

    delay_millisec(250); /* 0.25 second delay before next read */*/

    /

    a delay function in here to prevent retriggering ! */

    R = 0xffff; /* clear all pending interrupts */

    {cIER = 2; /* disable all in

    //puts("e

    ch = read_keypad_rowj(); /* read the first rowp

    ch = read_keypad_rowk(); /* read the second row onlyprintf("%c\n",ch);delay_millisec(250); /* 0.25 second delay before next read */ch = read_keypad_rowl(); /* read the third row only */

    printf("%c\n",ch);delay_millisec(250); /* 0.25 second delay before next read */ch = read_keypad_rowm(); /* read the fourth row only *printf("%c\n",ch);delay_millisec(250); /* 0.25 second delay before next read */

    /* you may even needICIER |= 0x0020; /* re enable int 5 */}

  • 7/27/2019 RTS Finalone

    25/29

    25

    /***********************************************************/

    C code for Task 3 */keypad_lib . C */

    include "keypad_lib.h"

    ;/* note the students will have to create row2-row4 read

    utines */

    nt y; /* define local variable */

    signed int *dpr0 = (unsigned int *) 0xA0000000; /* 2nd external memory address */0xA0000008; /* 3rd external memory ad */

    dpr0 = 0x00; /* clear keypad inputs */

    *dpr2; /* read the output of the keypad matrix */bits to 0 */

    h one it is */

    if (y == 0x10)

    (y == 0x20)function return value for the key "2"*/

    ",temp);

    /*/*/* */

    /* C function for the keypad access *//* *//* *//************************************************************/#include #include "timer_lib.h"#char read_keypad_rowj()char read_keypad_rowk();

    rochar read_keypad_rowl();char read_keypad_rowm();

    char read_keypad_rowj(){ichar temp;ununsigned int *dpr2 = (unsigned int *)

    temp='x'; /* default value for when the key has not been recognised by this function*/**dpr0 = 0x01; /* energise only row 1 of the keypad matrix */y=y&=0xF0; /* mask to reset irrelevant

    if (y != 0) /* if one of the lines has been set, check whic{

    temp = '1'; /* function return value for the key "1" */iftemp = '2'; /*

    if (y == 0x40)temp = '3';

    if (y == 0x80)temp = 'F';

    //printf("%c\n}

    return(temp);

  • 7/27/2019 RTS Finalone

    26/29

    26

    }

    char read_keypad_rowk()

    nt y; /* define local variable */

    signed int *dpr0 = (unsigned int *) 0xA0000000; /* 2nd external memory address */0xA0000008; /* 3rd external memory ad */

    dpr0 = 0x00; /* clear keypad inputs */

    *dpr2; /* read the output of the keypad matrix */bits to 0 */

    h one it is */

    if (y == 0x10)

    (y == 0x20)function return value for the key "2"*/

    ",temp);

    ad_rowl()

    nt y; /* define local variable */

    signed int *dpr0 = (unsigned int *) 0xA0000000; /* 2nd external memory address */0xA0000008; /* 3rd external memory ad */

    dpr0 = 0x00; /* clear keypad inputs */

    *dpr2; /* read the output of the keypad matrix */bits to 0 */

    h one it is */

    {i

    char temp;ununsigned int *dpr2 = (unsigned int *)temp='x'; /* default value for when the key has not been recognised by this function*/**dpr0 = 0x02; /* energise only row 1 of the keypad matrix */y=y&=0xF0; /* mask to reset irrelevant

    if (y != 0) /* if one of the lines has been set, check whic{

    temp = '4'; /* function return value for the key "1" */iftemp = '5'; /*

    if (y == 0x40)temp = '6';

    if (y == 0x80)temp = 'E';

    //printf("%c\n

    }

    return(temp);}

    char read_keyp{ichar temp;ununsigned int *dpr2 = (unsigned int *)temp='x'; /* default value for when the key has not been recognised by this function*/**dpr0 = 0x04; /* energise only row 1 of the keypad matrix */y=y&=0xF0; /* mask to reset irrelevant

    if (y != 0) /* if one of the lines has been set, check whic{

  • 7/27/2019 RTS Finalone

    27/29

    27

    if (y == 0x10)

    (y == 0x20)function return value for the key "2"*/

    ",temp);

    ad_rowm()

    nt y; /* define local variable */

    signed int *dpr0 = (unsigned int *) 0xA0000000; /* 2nd external memory address */0xA0000008; /* 3rd external memory ad */

    dpr0 = 0x00; /* clear keypad inputs */

    *dpr2; /* read the output of the keypad matrix */bits to 0 */

    h one it is */

    if (y == 0x10)

    (y == 0x20)function return value for the key "2"*/

    ",temp);

    temp = '7'; /* function return value for the key "1" */iftemp = '8'; /*

    if (y == 0x40)

    temp = '9';if (y == 0x80)temp = 'D';

    //printf("%c\n}

    return(temp);}

    char read_keyp{

    ichar temp;ununsigned int *dpr2 = (unsigned int *)temp='x'; /* default value for when the key has not been recognised by this function*/**dpr0 = 0x08; /* energise only row 1 of the keypad matrix */y=y&=0xF0; /* mask to reset irrelevant

    if (y != 0) /* if one of the lines has been set, check whic{

    temp = 'A'; /* function return value for the key "1" */iftemp = '0'; /*

    if (y == 0x40)temp = 'B';

    if (y == 0x80)temp = 'C';

    //printf("%c\n}

    return(temp);}

  • 7/27/2019 RTS Finalone

    28/29

    28

    *****************************************/C code for Task 4 */

    keypad . C */

    include "c6711dsk.h"h"

    lib.h"

    declare the interrupt service routine */ER";

    UTTON";

    ) 0xA0000000;r *output_latch = (char *) 0xA0000010;

    le char *input_latch = (char *) 0xA000000C;

    dpr0 = 0x00;

    R = 0x100; /* global disable maskable interrupts */disabled (global)!\n");

    R = 0xFFFF; /* clear all pending interrupts */g the Interrupt*/

    isplayon_cursorblink();(msg1);i++)

    t 6 (external interrupt 6)*/idual)!\n");

    /*/*/*

    /******************************************/

    #include #include ##include "timer_lib.#include "keypad_#include "display_lib.h"void keypad_isr(); /*char msg1[]="VOLTMET

    char msg2[]="PRESS A Bchar msg3[]="PRESS ANY KEY";char ch[];int i;unsigned int *dpr0 = (unsigned int *volatile chavolati/** ======== main ========*/

    void main(){*

    CSputs("interrupts

    IER = 2; /* disable all interrupts*/

    ICputs("program is starting \n"); /*Loadin

    init_display();load_modes(); /*Loading the display*/dfor(i=0;i

  • 7/27/2019 RTS Finalone

    29/29

    29

    CSR |= 0x1; /*global interrupt enable*/

    *dpr0 = 0x0F; /*Energise all inputs for keypad interrupt*/

    terrupt void keypad_isr()

    loat var;

    isable all interrupts*/

    elay_millisec(50); /*Delay to stop retriggering of int5*/

    =1;

    ;

    x = *input_latch;

    ar);

    ding the display*/

    for(i=0;i