;*************************************************************** ;* Project Name: ;* Project Description : ; ;* Author: ;* Lab_group: ;* Last edited: ; ;*************************************************************** ;* "AVR ExperimentBoard" port assignment information: ;***************************************************************************** ;* ;* LED0(P):PortC.0 LED4(P):PortC.4 ;* LED1(P):PortC.1 LED5(P):PortC.5 ;* LED2(S):PortC.2 LED6(S):PortC.6 ;* LED3(Z):PortC.3 LED7(Z):PortC.7 INT:PortE.4 ;* ;* SW0:PortG.0 SW1:PortG.1 SW2:PortG.4 SW3:PortG.3 ;* ;* BT0:PortE.5 BT1:PortE.6 BT2:PortE.7 BT3:PortB.7 ;* ;***************************************************************************** ;* ;* AIN:PortF.0 NTK:PortF.1 OPTO:PortF.2 POT:PortF.3 ;* (temperature) (light) ;***************************************************************************** ;* ;* LCD1(VSS) = GND LCD9(DB2): - ;* LCD2(VDD) = VCC LCD10(DB3): - ;* LCD3(VO ) = GND LCD11(DB4): PortA.4 ;* LCD4(RS ) = PortA.0 LCD12(DB5): PortA.5 ;* LCD5(R/W) = GND LCD13(DB6): PortA.6 ;* LCD6(E ) = PortA.1 LCD14(DB7): PortA.7 ;* LCD7(DB0) = - LCD15(BLA): VCC ;* LCD8(DB1) = - LCD16(BLK): PortB.5 (1=Backlight ON) ;* ;***************************************************************************** .nolist .include "m128def.inc" ; ATMega 128 definitions .list ;***** Constants ***** .equ tconst = 25 ; timing constant (T = 25*10 msec) ;***** Registers ***** .def temp = r16 ; generic temporary values .def sstate = r17 ; SW3 state ;***************************************************************************** ;* Reset & IT vectors ;***************************************************************************** .cseg .org 0x0000 ; Start of code segment jmp main ; Reset vector jmp dummy ; EXTINT0 Handler jmp dummy ; EXTINT1 Handler jmp dummy ; EXTINT2 Handler jmp dummy ; EXTINT3 Handler jmp dummy ; EXTINT4 Handler (INT button) jmp dummy ; EXTINT5 Handler jmp dummy ; EXTINT6 Handler jmp dummy ; EXTINT7 Handler jmp dummy ; Timer2 Compare Match Handler jmp dummy ; Timer2 Overflow Handler jmp dummy ; Timer1 Capture Event Handler jmp dummy ; Timer1 Compare Match A Handler jmp dummy ; Timer1 Compare Match B Handler jmp dummy ; Timer1 Overflow Handler jmp t0it ; Timer0 Compare Match Handler jmp dummy ; Timer0 Overflow Handler jmp dummy ; SPI Transfer Complete Handler jmp dummy ; USART0 RX Complete Handler jmp dummy ; USART0 Data Register Empty Hanlder jmp dummy ; USART0 TX Complete Handler jmp dummy ; ADC Conversion Complete Handler jmp dummy ; EEPROM Ready Hanlder jmp dummy ; Analog Comparator Handler jmp dummy ; Timer1 Compare Match C Handler jmp dummy ; Timer3 Capture Event Handler jmp dummy ; Timer3 Compare Match A Handler jmp dummy ; Timer3 Compare Match B Handler jmp dummy ; Timer3 Compare Match C Handler jmp dummy ; Timer3 Overflow Handler jmp dummy ; USART1 RX Complete Handler jmp dummy ; USART1 Data Register Empty Hanlder jmp dummy ; USART1 TX Complete Handler jmp dummy ; Two-wire Serial Interface Handler jmp dummy ; Store Program Memory Ready Handler ;***************************************************************************** ;* Main program ;***************************************************************************** .org 0x0046 ;***** Stack initialization ***** main: ldi temp,LOW(RAMEND) ; RAMEND = RAM end address out SPL,temp ; (see "m128def.inc") ldi temp,HIGH(RAMEND) out SPH,temp ;***** Port initialization ***** ;*** PORTC.0-7: LED0-7 *** ldi temp,0b11111111 ; all bits as output out DDRC,temp ; PORTC as output ;*** PORTG.0,1,3,4: SW 0,1,3,2 *** ldi temp,0b00000000 ; all bits as input sts DDRG,temp ; PORTG as input ldi temp,0b11111111 ; pull-up enabled (not required) sts PORTG,temp ; PORTG as input ;***** Timer 0 initialization ***** ldi temp,0b00001111 ; 0....... ; FOC=0 ; .0..1... ; WGM=10 (Clear Timer on Compare Match mode) ; ..00.... ; COM=00 (output disabled) ; .....111 ; CS0=111 (CLK/1024) out TCCR0,temp ; Timer 0 TCCR0 register ldi temp,108 ; 11059200Hz/1024 = 108*100 out OCR0,temp ; Timer 0 OCR0 register ldi temp,0b00000010 ; 000000.. ; Timer2,1 IT disabled ; ......1. ; OCIE0=1 Output Compare Interrupt Enabled ; .......0 ; TOIE0=0 Timer Overflow Interrupt Enabled out TIMSK,temp ; Timer IT Mask register sei ; enable global ITs ;***************************************************************************** ;***** read SW3 ***** loop: lds sstate,PING ; load SW3 state jmp loop ;***************************************************************************** ;* 10 msec Timer IT rutin ;***************************************************************************** .dseg ; count: .byte tconst ; 1 byte allocated in SRAM for timer counter ;count: .db tconst ; alternative format for AVR2 assembler ; AVR2 assembly selection: Project/AVR Assembler Setup .cseg t0it: push temp ; store register on stack in temp,SREG ; load SREG into register push temp ; store SREG contents on stack lds temp,count ; timer counter into register dec temp ; sts count,temp ; decrement and store brne t0ite ; skip next instructions if still not 0 ldi temp,tconst ; reinitialize counter sts count,temp in temp,PORTC ; read current LED output clc sbrs sstate,3 ; is SW3 active? (...=0) jmp t0it0 ; jump if yes rol temp ; SW3=0: LEDs step forward brcs t0it1 sbr temp,1 jmp t0it1 ; skip SW3=1 (t0it0) part t0it0: ror temp ; SW3=1: LEDs step backward brcs t0it1 sbr temp,128 t0it1: out PORTC,temp ; set LEDs to new value t0ite: pop temp ; revert register contents out SREG,temp pop temp dummy: reti ;*****************************************************************************