0% found this document useful (0 votes)
15 views3 pages

Enel3dsh1 Lab4

This practical involves using an 8515 microcontroller to create a digital clock that communicates with a PC via USART. Students must prepare by familiarizing themselves with the microcontroller, assembly programming, and the necessary connections, as well as completing a specific code section before the lab. The practical includes features such as time display updates and user input for incrementing hours and minutes through a serial terminal application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Enel3dsh1 Lab4

This practical involves using an 8515 microcontroller to create a digital clock that communicates with a PC via USART. Students must prepare by familiarizing themselves with the microcontroller, assembly programming, and the necessary connections, as well as completing a specific code section before the lab. The practical includes features such as time display updates and user input for incrementing hours and minutes through a serial terminal application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

UNIVERSITY OF KWAZULU-NATAL

School of Electrical, Electronic & Computer Engineering

Course : DIGITAL SYSTEMS


Code : ENEL3DSH1
Practical No. : : DS4
Title : 8515 MICRO CONTROLLER LAB 4 – Serial communication and RTC

INTRODUCTION

This practical provides an opportunity to experiment further with a simple 8515-based microcontroller
system. In this lab you will use Timer 1 in CTC mode and the USART to transmit data to a PC. The PC
will run a serial terminal application such as HyperTerminal and display the data sent via the AVR
USART. Each group will be supplied with an 8515 microcontroller board consisting of a microcontroller
and a virtual serial port over a USB (FT232RL-based) connection to the PC.

PREPARATION REQUIRED.

1. Familiarize yourself with the 8515 microcontroller system, assembly language programming and
the AVR instruction set details. You should be able to answer any questions posed by the lab
demonstrator relating to these aspects.
2. Familiarize yourself with the system connections in preparation for writing the required program for
a digital clock. You should be able to answer any questions posed by the lab demonstrator relating
to these aspects.
3. Complete the section UpdateDigits that updates the ASCII clock digits “HH:MM:SS”. The
subroutine will be marked by the demonstrator. More marks will be given if you avoid doing a
division.

NB: A significant amount of preparation is required to complete this practical in the time available. This
preparation cannot be done satisfactorily by the average person in a single evening. The complete
code should be written before coming in for the practical.

PRACTICAL WORK: DEVELOPMENT OF A DIGITAL CLOCK

Deploy the above alarm clock. You are expected to research how to configure HyperTerminal to
connect with your USART. Display the time and show that it updates all digits correctly. Show the
following.
After HH:MM:59 - SS clears and MM is incremented
After HH:59:59 - MM and SS clears and HH is incremented
After 23:59:59 - we return to 00:00:00
The less significant hour digit is interesting as it runs from 0 to 9 when the more significant hour digit is
0 or 1. But it runs from 0 to 3 when the more significant hour digit is 2. Show that this works.

Having completed the above, you should add more features to the code. Such as: typing ‘H’ in
HyperTerminal increments the hours, and typing ‘M’ increments the minutes. This will require a simple
receive routine.

1
/*
* EL3DS4lab.asm
* Created: 2012/04/19 09:33:05 AM
* Author: bnaido
*/

.include "m8515def.inc"
.include "Mymacros.asm"

.def temp=r16 ;temporary register


.def counter=r17 ;hold the display count
.def HH=r18 ;upper hours digit
.def HL=r19 ;Lower hours digit
.def MH=r20 ;upper minutes digit
.def ML=r21 ;Lower minutes digit
.def SH=r22 ;upper seconds digit
.def SL=r23 ;Lower seconds digit
.def Separator=r24 ;Hold time separator symbol
.def TXcharCount=r25 ;Total number of characters to transmit
;WARNING: do not use R27:R26 as these are being used as the X reg.

.dseg
.org 0x090
DisplayBuf: .byte 9 ;reserve 9 bytes to store "HH:MM:SS" + carriage return
.cseg

;***********Interrupt vector table*************


.org 0x0000
rjmp Reset ;reset vector
.org 0x0004
rjmp ClocktickISR ;Timer 1 compare match A vector
.org 0x000B
rjmp TxMsgISR ;Uart transmit complete interrupt vector

.org 0x0020
Reset:
;***setup the stack***
ldio SPH,high(RAMEND),temp
ldio SPL,low(RAMEND),temp

;****Setup Timer 1 for Compare Match A (5 Steps)****


; assuming a 1MHz system clock, and /64 prescaler
; we need a target count of 15624 to get a 1Hz interrupt
;STEP 1: setup prescaler to divide by 64
;note all TCCR1A and TCCR1B bits clear by default
setbits TCCR1B,0b00000011,temp ; CS12=0, CS11=1, CS10=1
;STEP 2: Setup timer mode to CTC (Clear Timer on Compare-matchA)
setbits TCCR1B,0b00001000,temp ;WGM12=1 WGM13=0 WGM11=0 WGM10=0
;STEP 3: Setup timer port access so that no port pins are driven by the timer
;Default values in TCCR1A are for normal port operation - no need to modify
;STEP 4: setup target count to give a 1Hz interrupt
ldio OCR1AH,high(15624),temp ;high byte
ldio OCR1AL,low(15624),temp ;low byte
;STEP 5: enable the Clear Timer on Comp Match A interrupt
setbits TIMSK,0b01000000,temp ;set OCIE1A

;****Setup the USART (2 Steps)****


;STEP 1: Setup transmission
;TXCIE is set to enable TX complete interrupts
;TXEN is set to enable the transmitter
;USCRA and USCRC are left in their default states
setbits UCSRB,0b01001000,temp ;TXCIE=bit6, TXEN=bit3
;STEP 2: Set the baud rate assuming 1MHz system clock
;UBBR=25 set Baud rate to 2400 bps with 0.2% error
ldio UBRRL,25,temp ;no need to change UBRRH

2
sei ;enable the interrupt subsystem

;Here we set initial values for our clock


ldi Separator,':' ;use a colon to separate HH:MM:SS
ldi SL,5
ldi SH,5
ldi ML,9
ldi MH,5
ldi HL,3
ldi HH,2

Mainloop: rjmp Mainloop ;endless background loop

;The clock tick ISR increments the count on Port C once per second
ClocktickISR:
rcall UpdateDigits
ldi TXcharCount,9 ;prepare to transmit 8 charaters + CR
ld temp,X+ ;start transmission of time string
out UDR,temp
dec TXcharCount
reti

UpdateDigits:
;Recalculate the values for HH:MM:SS after every second. The display is in 24hr format
;rewind the pointer to the DSEG table DisplayBuf
;Convert the numeric values to their ASCII symbols by adding $30
;Store the converted values to the DSEG table. (The Macro StoreNUM2ASC may help!!!)
;the table now contains H,H,:,M,M,:,S,S,13 - 9 ASCII values where 13 in the carriage
;return value. This returns the cursor to the original position so the next time string can
;overwrite the previous one and the clock stays in the same place on the screen.
ret

;***********************Transmit Interrupt service routine**************************


;Service routine that is run after the last charater transmission completes
;This routine loads the next character from the table and sends it.
;If we are at the end of the message table, we exit and do nothing.
;**********************************************************************************
TxMsgISR:
;Check if end of message is reached
cpi TXcharCount,0 ;stop if count = 0
breq ISR_Done
NextChar:
ld temp,X+ ;continue transmission of string pointed to by X
out UDR,temp
dec TXcharCount ;decrement count and stop at zero
ISR_Done:
reti

You might also like