Sie sind auf Seite 1von 8

Introduction The aim of this assignment is design a Digital Alarm Clock and by the use Renesas M16C family

microcontroller development board, operation of the designed watch can be demonstrated. The board will be connected to the PC. The High performance embedded Workshop (HEW), will be used to program and debug microcontroller. By the use of this software installed in a PC, complete sequence of operation of digital alarm clock will be demonstrated. The board will be programmed using C language which is considered as preferable high level language in many embedded systems application. Design description will be demonstrated by implementing state diagram of the system. By the use of designed state diagram, C program algorithm can be produced. Different I/O interrupts and timers will be configured and used in this assignment. This will achieved by proper configuration of special function registers (SFRs). To demonstrate flexibility, portability and efficient of C language, efficient programming technique will adopted in order to minimize size of the code while maximizing the execution time.

Special Function Registers Configuration Timers In M16C timers are classified basing on function; either timer A or timer B, also timer A supports the following four modes. Except in event counter mode, timers A0 to A4 all have the same function. Use the TMOD1 to TMOD0 bits of TAiMR register ( i = 0 to 4) to select the desired mode. Timer mode. Event counter mode. One-shot timer mode. Pulse width modulation (PWM) mode. In this assignment timer A will configured to operate basing on the requirements. To achieve this, following table will be used as guidance.

Figure 1: TA0MR to TA4MR Registers In designing a digital alarm clock, the main requirement is one second interrupt interval, to achieve this, the timer must be configured to give output of 1 sec from clock frequency of 24MHz. But due to limitation of maximum interrupt interval in16bit counter (65536 counts), two Timers will be cascade to meet 1 second interrupt interval. The first thing to do is to select count source from list of count source available in M16C (f1, f8, f32 or fc32). In this design f32 was selected, then pre-loaded value 0f 37500 was selected to set the first interrupt interval at 50ms using the formula below; 1 reload value = interrupt_ interval f Since in this design long interval (1 second interval) is needed, second timer configured in event mode with pre-loaded value of 20 will be cascaded in order to achieve one second interrupt interval required in the design..

Timers Configuration Timer Mode Is achieved by setting required bits in Timer register selected. In this design TAOMR=0x80 is set to indicate that the register is configured to operate in in timer mode .This is explained in details in figure below;

Figure 2:Configuration of Timer TA0 in timer mode Event Mode Is achieved by setting required bits in Timer register selected. In this design TA1MR=0x01 is set to indicate that the register is configured to operate in in event mode .This is explained in details in figure below;

Figure 3: Configuration Timer TA1 in Event Mode

Interrupt Control Register In order to achieve interrupt in M16C, Interrupt control register is configured to allow selected priority to handle interrupt. In this design priority is set to level 4,as shown in figure below;

Figure 4: Priority Level selection Trigger Select Register To allow cascaded timers to function, trigger select register is configured and used to link TA0 and TA1. By setting the required bits in this register determines the event that causes the particular timer to count. In this design, TRGSR=0x02 is set to show that, underflow of TA0 cause event on TA1.The configuration is shown on figure below;

Figure 5: Configuration Trigger select register

Start/Stop Register To start counting, Start/stop Register is set to enable count start flag. In this design is declared as TABSR_1=1 and TABSR_0=1 as shown below.

Figure 6: Count start flag configuration Input/output Ports Configuration


One of the SFR registers associated with basic I/O, and this is the Port Direction Register, In order to be

used as output two Pins of port 5 are configured to be used as outputs; P5D_0=1 P5D_1=1

Other Registers and Ports Some of the SFRs used in the design was already configured in a given template, so there are not included in this report Design Approach Design specification Basing on the design specification, Digital alarm clock contains the following hardware to be configured. This was achieved by configuring SFRs to be used. LCD- for displaying required information. LED-for indicating alarm off/on conditions. Three buttons (button1, button2 and button3). In software section the following condition will be designed to meet specification of the design. Alarm can be set and cleared in Normal display. When alarm is set, it can be cleared in by any of three buttons.

When Alarm is set and LED is flashing, and no button is pressed for one minute the LED will turn of automatic and take alarm out of set condition. When user take the application in state more than Normal display, If there is no any activity for a period of 10 seconds, the system will reset back to Normal display. In order to display day of the week, separate function will used to check every time when any changes is detected and update everything automatically. This facility will also check if year is leap year or not and update instantly. To implement the design basing on the specification provided State diagram was designed. To control the transition from one state to another, three buttons was configured. Function of each button at each button at each state is shown clearly in state diagram provided in appendix. Code Explanation The complete program needed for digital alarm clock was divided into the following functions; Main function. Keyscan function. Alarm control function. Update time function. Other functions provided in the template. Operation The main function was implemented basing on the state diagram designed. When program is executed, the first part of program to be displayed in LCD is Normal display. Basing on this design, at Normal display, LCD will display day of the week, date, month, year, Normal time and alarm status (set/not set). Basing on the design the system will stay in this state as long as no button is placed. When any of the three buttons is placed, the keyscan function will be executed to check validity of the placed. If the button is placed is varied (not debouncing), the function will check to identify the button. When this process is done, value corresponding to the button pressed will be returned to the main function. When button1 is pressed, the returned value is A. When button2 is pressed, the returned value is B. When button3 is pressed, the returned value is C.

In Normal display. When button1 is placed, the Normal display will change to Alarm display. When in Alarm display pressing button1 will return display to Normal display.

In Alarm display When button2 is placed, state will change to Set Alarm hour state and when button2 is pressed again it will move to Set Alarm min state. In these two states When button3 is pressed value variable in the corresponding state will be incremented. When button1 is pressed it will return the system in Normal display. Also when system is in Set Alarm min, by pressing button2, system will be returned to Normal display When in Normal display When button3 is pressed, the alarm will be set. If alarm flag is set, Alarm control function will be checked continuously to see if system time is equal to Alarm time. If the condition is true, the Alarm control function will be executed to flash LEDs on and off. At this condition, any of three buttons can be used to switch off alarm. But if there is no user interaction for one minute, the alarm will switch off automatic since the condition used to trigger the alarm is no longer true. When in Normal display Button2 will be used to move the system from Normal display state, Set Hour state,.,back to Normal display. When system is in state other than Normal state, button1 will be used to reset system back to Normal display by user interaction. But if the system is in state other than Normal display, and there is no user interaction, the interrupt of 10 sec will be used reset the system to Normal display. Button3 will be used to increment value of variables in the corresponding state. When there is any change in system time or date, update_time function will be executed and evaluate and return name of the day corresponding to the set value. Before it updates the information, the function check to see if is leap year or not. Conclusion After completion of the program write-up and debugging, the system functionality was tested. The system is working as expected. All functions designed operate as required. In this assignment, utilization of different features contained in Renesas M16C Microcontroller have been demonstrated clearly. Also usefulness of interrupt in system (program) have been demonstrated.

Das könnte Ihnen auch gefallen