The Program Written by me with my other four Class mate During 2nd Year Class Project in AVR-Assembly Language: 

Full Program

;***********************************************************

;*            Project Name:Naive Digital Synchronizer                                                 *

;*            Written by:Group 4                                                                                         *

;*            Date:11.06.2009                                                                                                *

;*            Version: 1.00                                                                                                      *

;*            For AVR: ATmega32                                                                                        *

;*            Clock Frequency: 4.00MHz                                                                           *

;*            Group Members:061041,061049,061050,061051,061052                 *

;***********************************************************

;  This program is free software: you can redistribute it and/or modify

;  it under the terms of the GNU General Public License as published by

; the Free Software Foundation, either version 3 of the License, or

; (at your option) any later version.

 

; This program is distributed in the hope that it will be useful,

;  but WITHOUT ANY WARRANTY; without even the implied warranty of

;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

;  GNU General Public License for more details.

 

;  You should have received a copy of the GNU General Public License

;  along with this program.  If not, see <http://www.gnu.org/licenses/>.

 

;***********including header file for atmega32*******

.include "m32def.inc"

;**********defining registers.***********************

.def today                           =r1

.def second                        =r2

.def min                               =r3

.def hour                             =r4

.def ampm                          =r5

.def cycle                             =r6

.def date                             =r7

.def seven                          =r8

.def f_digit                          =r9

.def s_digit                         =r10

.def yearl                             =r11

.def zero                              =r12

.def ten                                                =r13

.def howmtimes              =r14

.def divideby                     =r15

.def general                       =r16

.def day                                               =r17

.def month                         =r18

.def c_month                    =r19

.def c_day                           =r20                       ;which day A/B/C/D/E?

.def split                              =r21

.def control                        =r22

.def rawdata                      =r23

.def delay1                         =r24

.def delay2                         =r25

;Some additional information

;xl=counting

;xh=cursor point counting

;yh=cursor point indicator

;**********defining bit number for lcd control************

.equ       LCD_RS = 3                                          ;Portd.3

.equ       LCD_E   = 2                                          ;portd.2

.equ       startn    =$13

.equ       endx      =$0

;***************************************************

ldi general,0xff

out ddrd,general                                              ;set Portd as output

nop

;*******************************

ldi general,0x7                                                   ;loading initial value to all

mov seven,general

ldi general,$0

mov zero,general

ldi general,$a

mov ten,general

ldi xh,1                                                                  ;cursor point count home

;************initializing all values****************

ldi general,0x0                                                   ;clock at 12:00:00 AM

mov second,general

mov ampm,general                                        ;AM=00,PM=01

ldi general,59

mov min,general

ldi general,0xb

mov hour,general

;****************************************************

ldi general,0x01                                                                ;Date at 01-06-2009

mov date,general

ldi general,0x06

mov month,general

ldi general,0x09

mov yearl,general

;****************************************************

ldi general, 0x00                                               ;Day starting at 'A' day

mov c_day,general

;****************************************************

ldi general, 0x06                                               ;Cycle starting at "06"

mov cycle,general

;***************************************************

                ldi           general, low(RAMEND)

                out         SPL, general

                ldi           general, high(RAMEND)

                out         SPH, general

;###############SRAM initialization####################

clr yh

ldi yl,0x90                                                            ;Period code 0 means first code

ldi general,0

st y,general

clr yh

ldi yl,0x91                                                            ;scroll counter

ldi general,0

st y,general

;0x92     = temporary subcode

;0x93     = temporary roomcode

;###################################################

rcall        LCD_init                                               ;initialize lcd. it needs initialization only for once

ldi general,0b11000111                                  ;Porta.0,porta.1,porta.2=output

out ddra,general                                              ;porta.3,porta.4,porta.5=input

nop

sbi porta,0                                                           ;set bit 0 in porta

nop

;**************Writing our Credit to LCD*******************

ldi           control, 0x00|0x80                          ;cursor in 1st row first column

rcall        lcdcontrol

ldi zh,high(2*credit1)                                     ;Writing to lcd the Designation

ldi zl,low(2*credit1)

ldi xl,20                                                                 ;xl  as counter

credit1x:

lpm general,z+

rcall LCD_write

dec xl

brne credit1x

ldi           control, 0x40|0x80                          ;cursor in 2nd row first column

rcall        lcdcontrol

ldi zh,high(2*credit2)                                     ;Writing to lcd the Designation

ldi zl,low(2*credit2)

ldi xl,20                                                                 ;xl  as counter

credit2x:

lpm general,z+

rcall LCD_write

dec xl

brne credit2x

ldi           control, 0x14|0x80                          ;cursor in 3rd row first column

rcall        lcdcontrol

ldi zh,high(2*members1)                             ;Writing to lcd the Designation

zl,low(2*members1)

xl,20                                                                       ;xl as counter

members1x:

lpm general,z+

rcall LCD_write

dec xl

brne members1x

ldi           control, 0x54|0x80                          ;cursor in 4th row first column

rcall        lcdcontrol

ldi zh,high(2*members2)                             ;Writing to lcd the Designation

ldi zl,low(2*members2)

ldi xl,20                                                                 ;xl as counter

members2x:

lpm general,z+

rcall LCD_write

dec xl

brne members2x

ldi xl,25

_3s:

rcall _30ms

dec xl

brne _3s

ldi control,$01                                                    ;cursor home,clear lcd

rcall lcdcontrol

;***********Writing Credit to LCD is complete**********

rjmp start                                                            ;From here jump to start of program

inccount:                                                             ;cursor increamenting section

rcall _30ms                                                          ;for debouncing 30ms

inc xh

cpi xh,13                                                              ;compare it to 13

breq setcur

rjmp cur

setcur:

ldi xh,1

cur:

ldi zh,high(2*_count)

ldi zl,low(2*_count)

clc

add zl,xh

adc zh,zero

lpm yh,z

mov control,yh

rcall lcdcontrol

rcall LCD_delay

rjmp sd

;************count decreasing*******************

deccount:

rcall _30ms                                                          ;for debouncing 30ms

dec xh

cpi xh,0                                                                 ;compare it to 0

breq setcur0

rjmp cur0

setcur0:

ldi xh,12

cur0:

ldi zh,high(2*_count)

ldi zl,low(2*_count)

clc

add zl,xh

adc zh,zero

lpm yh,z

mov control,yh

rcall lcdcontrol

rcall LCD_delay

rjmp sd

;***********30 ms delay unit*************

_30ms:

ldi general,0xff                                                  ;200ms delay name is different

mov delay1,general

ldi general,0xae

mov delay2,general

ldi xl,2

x12:

dec delay1

brne x12

dec delay2

brne x12

dec xl

brne x12

ret                                                                          ;completes here

inccountx:

rjmp inccount

set_done:

                rcall _30ms

                rcall        LCD_delay

                ldi zh,high(2*_count)

                ldi zl,low(2*_count)

                clc

                add zl,xh

                adc zh,zero

                lpm yh,z

                mov control,yh

                rcall lcdcontrol

                ldi           control, 0x0f                       ;cursor visible and blinking

                rcall        lcdcontrol

;read eeprom

rcall makeadd                                                    ;address in general

push yh                                                                                ;don't touch yh, never ever!

clr yh

mov yl,general

push general                                                      ;save the address

rcall eeprom_read                                           ;code in general

ldi yl,0x92

st y,general                                                        ;store subcode

pop general

inc general

mov yl,general

rcall eeprom_read                                           ;code in general

ldi yl,0x93

st y,general                                                        ;store room code

pop yh

sd:                                                                          ;set/done button check

rcall _30ms

sbi porta,0

nop

in general,pina                                                  ;checking for left button pressed?

andi general,$09                                               ;0000 1001

cpi general,$09

breq inccountx

in general,pina                                                  ;checking for right button pressed?

andi general,$11                                               ;0001 0001

cpi general,$11

breq deccount

in general,pina                                                  ;checking for done button pressed?

andi general,$21                                               ;0010 0001

cpi general,$21

breq start1x

cbi porta,0

nop

sbi porta,1

nop

in general,pina                                                  ;checking for checking for increament button

andi general,$0a                                               ;pressed?

cpi general,$0a                                                  ;0000 1010

breq incment

in general,pina                                                  ;checking for decreament button pressed

andi general,$22                                               ;0010 0010

cpi general,$22

breq decment

cbi porta,1

nop                                                                        ;0001 0100           ;14

sbi porta,2

nop

in general,pina                                                  ;checking for save button pressed

andi general,$14

cpi general,$14

breq savex

cbi porta,2

nop

rjmp sd

savex:

rjmp save

start1x:

rjmp start1

incment:                                                              ;the section for increamenting

cpi yh,$15|$80                                                   ;is cursor on hour box?

breq inchour                                                      ;if yes then jump to inc hour section

cpi yh,$18|$80

breq incmin                                                        ;jump to inc min section

cpi yh,$1b|$80

breq incsecond

cpi yh,$1c|$80

breq incampm                                                   ;considering the ampm

cpi yh,$26|$80

breq inccycle

cpi yh,$55|$80

breq incday

cpi yh,$58|$80

breq incmonth

cpi yh,$5d|$80

breq incyearl

cpi yh,$63|$80

breq inccday

cpi yh,$40|$80                                                   ;inc period

breq incperiod

cpi yh,$4a|$80                                                   ;inc subject

breq incsub

cpi yh,$53|$80                                                   ;inc room

breq incroom

rjmp sd                                                                 ;if no maches found then jump to sd

inchour:

rjmp inchourx

incmin:

rjmp incminx

incsecond:

rjmp incsecondx

incampm:

rjmp incampmx

inccycle:

rjmp inccyclex

incday:

rjmp incdayx

incmonth:

rjmp incmonthx

incyearl:

rjmp incyearlx

inccday:

rjmp inccdayx

incperiod:

rjmp incperiodx

incsub:

rjmp incsubx

incroom:

rjmp incroomx

decment:

cpi yh,$15|$80                                                   ;is cursor on hour box?

breq dechour                                                    ;if yes then jump to inc hour section

cpi yh,$18|$80

breq decmin                                                      ;jump to inc min section

cpi yh,$1b|$80

breq decsecond

cpi yh,$1c|$80

breq decampm                                                 ;considering the ampm

cpi yh,$26|$80

breq deccycle

cpi yh,$55|$80

breq decday

cpi yh,$58|$80

breq decmonth

cpi yh,$5d|$80

breq decyearl

cpi yh,$63|$80

breq deccday

cpi yh,$40|$80                                                   ;dec period

breq decperiod

cpi yh,$4a|$80                                                   ;dec subject

breq decsub

cpi yh,$53|$80                                                   ;dec room

breq decroom

rjmp sd                                                                 ;if no maches found then jump to sd

dechour:

rjmp dechourx

decmin:

rjmp decminx

decsecond:

rjmp decsecondx

decampm:

rjmp decampmx

deccycle:

rjmp deccyclex

decday:

rjmp decdayx

decmonth:

rjmp decmonthx

decyearl:

rjmp decyearlx

deccday:

rjmp deccdayx

decperiod:

rjmp decperiodx

decsub:

rjmp decsubx

decroom:

rjmp decroomx

save:                                                                     ;for saving in eeprom

push yh

rcall _30ms                                                          ;for debouncing

rcall makeadd                                                    ;will make a address depending on period and day

mov control,general                                       ;address in general

clr yh

ldi yl,0x92                                                            ;subcode

ld general,y                                                        ;read the subcode from SRAM

mov yl,control

rcall eeprom_write

inc control                                                           ;subject is in 0x93

ldi yl,0x93                                                            ;subcode

ld general,y                                                        ;read the subcode from SRAM

mov yl,control

rcall eeprom_write

ldi control, 0b00000010

rcall lcdcontrol                                                   ;cursor moved to first row

ldi general,0xff

rcall LCD_write

ldi general,'D'

rcall LCD_write

ldi general,'O'

rcall LCD_write

ldi general,'N'

rcall LCD_write

ldi general,'E'

rcall LCD_write

ldi general,0xff

rcall LCD_write

pop yh

rjmp sd

;**********start of increasing section***********************

inchourx:

inc hour

mov general,hour

cpi general,0xd                                                 ;compare hour to 13

breq sethour

hoursetted:

                ldi           control, 0x14|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,hour                                                   ;split hour

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x15|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

sethour:

ldi general,$01

mov hour,general

rjmp hoursetted

;*****************end of inc hour section********************             

incminx:

inc min

mov general,min

cpi general,60                                                    ;compare minute to 60

breq setmin

minsetted:

                ldi           control, 0x17|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,min                                                     ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x18|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

setmin:

ldi general,$01

mov min,general

rjmp minsetted

;*****************end of inc min section********************

incsecondx:

inc second

mov general,second

cpi general,60                                                    ;compare second to 60

breq setsecond

secondsetted:

                ldi           control, 0x1a|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,second                                              ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x1b|$80                            ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

setsecond:

ldi general,$01

mov second,general

rjmp secondsetted

;*****************end of inc second section********************

incampmx:

inc ampm

mov general,ampm

cpi general,2                                                      ;compare ampm to 2

breq setampm

ampmsetted:

                ldi           control, 0x1c|$80             ;Cursor will be in the same position        

                rcall        lcdcontrol

ldi zh,high(2*_ampm)

ldi zl,low(2*_ampm)

ldi xl,0x2                                                               ;xl as counter

ldi general,0x2

mul general,ampm                                          ;result is in r1:r0

clc

add zl,r0

adc zh,zero

todayx1:

lpm general,z+

rcall LCD_write

dec xl

brne todayx1

ldi           control, 0x1c|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

setampm:

ldi general,$00

mov ampm,general

rjmp ampmsetted

;*****************end of inc ampm section********************

inccyclex:

inc cycle

mov general,cycle

cpi general,14                                                    ;compare cycle to 14

breq setcycle

cyclesetted:

                ldi           control, 0x25|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,cycle                                                  ;split cycle

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x26|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

setcycle:

ldi general,$01

mov cycle,general

rjmp cyclesetted

;**************end of cycle setted************************

incdayx:

inc day

mov general,day

cpi general,31                                                    ;compare day to 31

breq setday

daysetted:

                ldi           control, 0x54|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,day                                                     ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x55|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

setday:

ldi general,$01

mov day,general

rjmp daysetted

;**************end of day setted************************

incmonthx:

inc month

mov general,month

cpi general,13                                                    ;compare month to 13

breq setmonth

monthsetted:

                ldi           control, 0x57|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,month                                               ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x58|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

setmonth:

ldi general,$01

mov month,general

rjmp monthsetted

;**************end of month setted************************

incyearlx:

inc yearl

mov general,yearl

cpi general,41                                                    ;compare month to 13

breq setyearl

yearlsetted:

                ldi           control, 0x5c|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,yearl                                                  ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x5d|$80                            ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

setyearl:

ldi general,$01

mov yearl,general

rjmp yearlsetted

;***************end of yearl increase*******************

inccdayx:

inc c_day

mov general,c_day

cpi general,5                                                      ;compare cycle day to 5

breq setc_day

c_daysetted:

                ldi           control, 0x63|$80             ;Cursor will be in the same position        

                rcall        lcdcontrol

ldi zh,high(2*c_dayx)

ldi zl,low(2*c_dayx)

clc

add zl,c_day

adc zh,zero

lpm general,z

rcall LCD_write

ldi           control, 0x63|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

setc_day:

ldi general,$00

mov c_day,general

rjmp c_daysetted

;****************set the period*******************************

incperiodx:

push yh                                                                                ;save yh for cursor movement

clr yh

ldi yl,$90

ld general,y

inc general

cpi general,9

breq speriod

periods:

clr yh

ldi yl,$90

st y,general

ldi zh,high(2*pcode)

ldi zl,low(2*pcode)

ldi control,3

mul control,general

clc

add zl,r0

adc zh,zero

ldi xl,3

pback:

lpm general,z+

rcall LCD_write

dec xl

brne pback

ldi           control, 0x40|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

pop yh

rjmp sd

speriod:

clr general

rjmp periods

;****************inc subject********************************

incsubx:

push yh

clr yh

ldi yl,0x92

ld general,y

inc general         

cpi general,47                                                    ;total subject 47 subcode-->0-46

breq sscode

sscodes:

clr yh

ldi yl,0x92

st y,general                                                        ;temorarily save subcode

;read subcode

ldi zh,high(2*subcode)

ldi zl,low(2*subcode)

ldi control,3

mul general,control

clc

add zl,r0

adc zh,zero

ldi xl,3

                ldi           control, 0x48|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

back1s:

lpm general,z+

rcall LCD_write

dec xl

brne back1s

                ldi           control, 0x4a|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

pop yh

rcall _30ms

rjmp sd

sscode:

ldi general,0

rjmp sscodes

;****************inc room code********************************

incroomx:

push yh

clr yh

ldi yl,0x93

ld general,y

inc general         

cpi general,16                                                    ;total room 16 subcode-->0-15

breq rcode

rcodes:

clr yh

ldi yl,0x93

st y,general                                                        ;temorarily save rcode

;read subcode

ldi zh,high(2*room)

ldi zl,low(2*room)

ldi control,3

mul general,control

clc

add zl,r0

adc zh,zero

ldi xl,3

                ldi           control, 0x51|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

rback:

lpm general,z+

rcall LCD_write

dec xl

brne rback

                ldi           control, 0x53|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

pop yh

rcall _30ms

rjmp sd

rcode:

ldi general,0

rjmp rcodes

;****************##################***************************

;**********start of decreasing section***********************

dechourx:

dec hour

mov general,hour

cpi general,-1                                                     ;compare hour to -1

breq nsethour

nhoursetted:

                ldi           control, 0x14|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,hour                                                   ;split hour

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x15|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

nsethour:

ldi general,12

mov hour,general

rjmp nhoursetted

;*****************end of inc hour section********************             

decminx:

dec min

mov general,min

cpi general,-1                                                     ;compare minute to 60

breq nsetmin

nminsetted:

                ldi           control, 0x17|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,min                                                     ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x18|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

nsetmin:

ldi general,59

mov min,general

rjmp nminsetted

;*****************end of inc min section********************

decsecondx:

dec second

mov general,second

cpi general,-1                                                     ;compare second to 60

breq nsetsecond

nsecondsetted:

                ldi           control, 0x1a|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,second                                              ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x1b|$80                            ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

nsetsecond:

ldi general,59

mov second,general

rjmp nsecondsetted

;*****************end of inc second section********************

decampmx:

dec ampm

mov general,ampm

cpi general,-1                                                     ;compare ampm to 2

breq nsetampm

nampmsetted:

                ldi           control, 0x1c|$80             ;Cursor will be in the same position        

                rcall        lcdcontrol

ldi zh,high(2*_ampm)

ldi zl,low(2*_ampm)

ldi xl,0x2                                                               ;xl as counter

ldi general,0x2

mul general,ampm                                          ;result is in r1:r0

clc

add zl,r0

adc zh,zero

ntodayx1:

lpm general,z+

rcall LCD_write

dec xl

brne ntodayx1

ldi           control, 0x1c|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

nsetampm:

ldi general,$01

mov ampm,general

rjmp nampmsetted

;*****************end of inc ampm section********************

deccyclex:

dec cycle

mov general,cycle

cpi general,-1                                                     ;compare cycle to 14

breq nsetcycle

ncyclesetted:

                ldi           control, 0x25|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,cycle                                                  ;split cycle

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x26|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

nsetcycle:

ldi general,$13

mov cycle,general

rjmp ncyclesetted

;**************end of cycle setted************************

decdayx:

dec day

mov general,day

cpi general,-1                                                     ;compare day to 31

breq nsetday

ndaysetted:

                ldi           control, 0x54|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,day                                                     ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x55|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

nsetday:

ldi general,30

mov day,general

rjmp ndaysetted

;**************end of day setted************************

decmonthx:

dec month

mov general,month

cpi general,-1                                                     ;compare month to 13

breq nsetmonth

nmonthsetted:

                ldi           control, 0x57|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,month                                               ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x58|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

nsetmonth:

ldi general,12

mov month,general

rjmp nmonthsetted

;**************end of month setted************************

decyearlx:

inc yearl

mov general,yearl

cpi general,8                                                      ;compare month to 13

breq nsetyearl

nyearlsetted:

                ldi           control, 0x5c|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

mov split,yearl                                                  ;split min

rcall section                                                        ;split it in two part to write LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi           control, 0x5d|$80                            ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

nsetyearl:

ldi general,9

mov yearl,general

rjmp nyearlsetted

;***************end of yearl increase*******************

deccdayx:

dec c_day

mov general,c_day

cpi general,-1                                                     ;compare cycle day to 5

breq nsetc_day

nc_daysetted:

                ldi           control, 0x63|$80             ;Cursor will be in the same position        

                rcall        lcdcontrol

ldi zh,high(2*c_dayx)

ldi zl,low(2*c_dayx)

clc

add zl,c_day

adc zh,zero

lpm general,z

rcall LCD_write

ldi           control, 0x63|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

rjmp sd

nsetc_day:

ldi general,5

mov c_day,general

rjmp nc_daysetted

;********************dec period*************************

decperiodx:

push yh                                                                                ;save yh for cursor movement

clr yh

ldi yl,$90

ld general,y

dec general

cpi general,0

breq nsperiod

nperiods:

clr yh

ldi yl,$90

st y,general                                                        ;save the period value

ldi zh,high(2*pcode)

ldi zl,low(2*pcode)

ldi control,3

mul control,general

clc

add zl,r0

adc zh,zero

ldi xl,3

npback:

lpm general,z+

rcall LCD_write

dec xl

brne npback

ldi           control, 0x40|$80                             ;now moving the cursor to the init position

rcall        lcdcontrol

rcall _30ms

pop yh

rjmp sd

 

nsperiod:

ldi general,8

rjmp nperiods

;***************dec subject********************************

decsubx:

push yh

clr yh

ldi yl,0x93

ld general,y

dec general       

cpi general,-1                                                     ;total subject 47 subcode-->0-46

breq nsscode

nsscodes:

clr yh

ldi yl,0x93

st y,general                                                        ;temorarily save subcode

;read subcode

ldi zh,high(2*subcode)

ldi zl,low(2*subcode)

ldi control,3

mul general,control

clc

add zl,r0

adc zh,zero

ldi xl,3

                ldi           control, 0x48|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

nback1s:

lpm general,z+

rcall LCD_write

dec xl

brne nback1s

                ldi           control, 0x4a|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

pop yh

rcall _30ms

rjmp sd

nsscode:

ldi general,46

rjmp nsscodes

;********************dec room code*************************

decroomx:

push yh

clr yh

ldi yl,0x93

ld general,y

dec general       

cpi general,-1                                                     ;total room 16 subcode-->0-15

breq nrcode

nrcodes:

clr yh

ldi yl,0x93

st y,general                                                        ;temorarily save rcode

;read subcode

ldi zh,high(2*room)

ldi zl,low(2*room)

ldi control,3

mul general,control

clc

add zl,r0

adc zh,zero

ldi xl,3

                ldi           control, 0x51|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

nrback:

lpm general,z+

rcall LCD_write

dec xl

brne nrback

                ldi           control, 0x53|$80             ;now moving the cursor just 1 bit ahead.              

                rcall        lcdcontrol

pop yh

rcall _30ms

rjmp sd

nrcode:

ldi general,15

rjmp nrcodes

;*******************###########******************************

set_donex:

rjmp set_done

 

start1:                                                                   ;here we are to jump to start

rcall _30ms                                                          ;delay 30ms for debouncing

ldi           control, 0x0c                                      ;make cursor invisible

rcall        lcdcontrol

sbi porta,0                                                           ;make PORTA.0 pin high

nop

ldi xh,1

;*****************starting of main programme*******************

start:                                                                     ;Main body of the Programe.

in general,pina                                                  ;check weather set button has been pressed or not

andi general,$20                                               ;0010 0000

cpi general,$20

breq set_donex

ldi           control, 0x14|0x80                          ;cursor in 3rd row first column

rcall        lcdcontrol

inc second                                                           ;increase second

;inc ampm                                                           ;modified here for fst test

;ldi general,0x2

;cp ampm,general

;brne no

;set

;inc day

;ldi general,0x0

;mov ampm,general

no:                                                                         ;label for help in upper section

mov general,second

cpi general,60

brne _min

ldi general,0x0

mov second,general

inc min

_min:

mov general,min

cpi general,60

brne _hourx

ldi general,0x0

mov min,general

inc hour                               

ldi general,0xc                                                   ;compare it to 12

cp hour,general

brne _hourx

inc ampm

ldi general,0x2                                                   ;from pm --> am fallen

cp ampm,general

brne _hourx

ldi general,0x0

mov ampm,general

set                                                                          ;set t flag to indicate day increased

inc day                                                                  ;and increase day

_hourx:

mov general,hour

cpi general,0xd                                                 ;compare hour to 13

brne _day

ldi general,0x1

mov hour, general

;stop c_day

cbi porta,0                                                           ;make low porta.0

nop

sbi porta,1                                                           ;make high porta.1

nop

in general,pina

andi general,$12

cpi general,$12

brne _xday                                                         ;button not pressed

clt                                                                           ;clear T flag

_xday:

cbi porta,1                          

nop

sbi porta,0                                                           ;now again set porta.0 pin high

nop

_day:

cpi day,29

breq _isfeb                                                         ;is february?

cpi day,30                                                            ;in february it will turn to 01

breq _30feb                                                       ;is february?

cpi day,31                                                            ;no, it is not february-

breq apr                                                               ;check whether it is Apr,June,Sep,Nov?

cpi day,32                                                            ;no, it is not either

breq jan

rjmp _yearl

jan:

inc month

ldi day,0x01

rjmp _yearl

apr:

ldi zh,high(2*_m4)

ldi zl,low(2*_m4)

ldi xl,0x4                                                               ;For loop 4 times

_x:

lpm general,z+

cp month,general

breq month4

dec xl

tst xl

breq _yearl

rjmp _x

month4:

inc month

ldi day,0x1

rjmp _yearl

_30feb:

cpi month,0x2                                                   ;is february

brne jump                                                           ;no it is not then go to yearl

inc month                                                            ;yes it is february, then inc month

ldi day,0x1                                                           ;inc day to 01

jump:

rjmp _yearl

_isfeb:

cpi month,0x2                                                   ;is february?

breq c_lp_year                                                 ;if yes, then is leap year?

rjmp _yearl

not_l_year:                                                        ;not leap year

inc month

ldi day,0x1

rjmp _yearl

c_lp_year:

ldi zh,high(2*l_year)

ldi zl,low(2*l_year)

ldi xl,0x8                                                               ;For loop 8 times

xx:

lpm        general,z+                                           ;load program memory to general

cp yearl,general

breq _yearl                                                         ;Yes leap year and branch

dec xl

tst xl                                                                      ;testing xl if it is zero?

breq not_l_year                                                               ;if equal to zero then branch.

rjmp xx

_yearl:

cpi month,13

brne c_day_calc

ldi month,0x1

inc yearl

c_day_calc:                                                         ;what day it is calcualtion starting.

mov c_month,month

cpi c_month,0x3

brlo fejan                                                            ;select month code

subi c_month,0x2

rjmp calculate

fejan:

add c_month,ten

calculate:

ldi zh,high(2*_c_day)

ldi zl,low(2*_c_day)

mov general,c_month

clc

add zl,general                                                    ;increamenting z pointer as c_month

adc zh,zero

lpm                                                                        ;load program memory

add r0,day                                                           ;[2.6m-0.2]+d+c

add r0,yearl                                                        ;[2.6m-0.2]+d+y+c

mov general,yearl

lsr general

lsr general                                                           ;divide by 4 of yearl

add r0,general                                                   ;[2.6m-0.2]+d+y+[y/4]+c

mov general,r0

subi general,40                                                 ;[2.6m-0.2]+d+y+[y/4]+c+[c/4]-40, c=20

brmi minus                                                         ;if result is minus then branch

cp general,seven

brge plus                                                             ;branch if greater than six

mov today,general                                          ;if inbetween 0-6 then direct jump to bar calc.

rjmp _bar

minus:

add general,seven

brmi minus

mov today,general

rjmp _bar                                                            ;now it is not minus

plus:

sub general,seven

cp general,seven                                             ;compare between seven and general

brge plus                                                             ;branch if general>=seven

mov today,general

rjmp _bar

_bar:

brtc LCD_show                                                  ;Moving day to today

cpi general,0x5                                                  ;day is Friday or saturday?

brlo x_bar          

clt                                                                           ;not above days then inc cycle day

rjmp LCD_show

x_bar:

clt                                                                           ;clear T flag

inc c_day

cpi c_day,0x5                                                     ;is c_day equal to five means to F not E?

brne LCD_show

ldi c_day,0x0

inc cycle                                                              

mov general,cycle

cpi general,14

breq scycle

rjmp LCD_show

scycle:

ldi general,1

LCD_show:

mov split,hour                                                   ;split hour

rcall section                                                        ;write to LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi general,':'

rcall LCD_write

mov split,min                                                     ;split minute

rcall section                                                        ;write to LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi general,':'

rcall LCD_write

mov split,second                                              ;split second

rcall section                                                        ;write to LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi zh,high(2*_ampm)                                    ;Writhing to lcd the am or pm

ldi zl,low(2*_ampm)

mov general,ampm

cpi          general,0x0       

ldi xl,0x2                                              

brne pm

                                                                                ;load the x low register for dec

am:

lpm general,z+

rcall LCD_write

dec xl

brne am

rjmp loop1

pm:

adiw zl,0x2

pm2:

lpm general,z+

rcall LCD_write

dec xl

brne pm2

rjmp loop1

loop1:

ldi general,0xff

rcall LCD_write

ldi zh,high(2*_cycle)                                       ;Writhing to lcd the name cycle

ldi zl,low(2*_cycle)

ldi xl,0x6

cyc:

lpm general,z+

rcall LCD_write

dec xl

brne cyc

;Now writing cycle number

mov split,cycle                                                  ;split hour

rcall section                                                        ;write to LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

;*********now move cursor to fourth line first char******

rcall        LCD_delay

ldi           control, 0x54|0x80                          ;fourth row 1st character

rcall        lcdcontrol

;now write date               

mov split,day                                                     ;split day

rcall section                                                        ;write to LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi general,'-'

rcall LCD_write

mov split,month                                               ;split day

rcall section                                                        ;write to LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi general,'-'

rcall LCD_write

ldi general,'2'

rcall LCD_write

ldi general,'0'

rcall LCD_write

mov split,yearl                                                  ;split day

rcall section                                                        ;write to LCD

mov general,f_digit

rcall LCD_write

mov general,s_digit                                        ;Now lcd like this XX

rcall LCD_write

ldi general,0xff

rcall LCD_write

;*********Writing LCD date is complete here***********

ldi zh,high(2*_dayx)                                       ;Writhing to lcd the name of day

ldi zl,low(2*_dayx)

ldi xl,0x4

dayx:

lpm general,z+

rcall LCD_write

dec xl

brne dayx

ldi zh,high(2*c_dayx)                                     ;Writhing to lcd the Day

ldi zl,low(2*c_dayx)

add zl,c_day

adc zh,zero

lpm general,z

rcall LCD_write

                                                                                ;Writing LCD the today name

;*************************************************

ldi general,0xff

rcall LCD_write

ldi zh,high(2*_today)                                     ;Writing to lcd today name day

ldi zl,low(2*_today)

ldi xl,0x3                                                               ;xl as counter

ldi general,0x3

mul general,today                                           ;result is in r1:r0

clc

add zl,r0

adc zh,zero

tdayx:

lpm general,z+

rcall LCD_write

dec xl

brne tdayx

;completed of writing Time,Date,C-day,Day,Cycle

;##################****************###########################

mov general,second

cpi general,7

breq incpcode

cpi general,14

breq incpcode

cpi general,21

breq incpcode

cpi general,28

breq incpcode

cpi general,35

breq incpcode

cpi general,42

breq incpcode

cpi general,49

breq incpcode

cpi general,56

breq incpcode

rjmp showpcode

incpcode:

clr yh

ldi yl,0x90                                                            ;Period code 0 means first code

ld general,y

inc general

cpi general,9

breq setgeneral

generalsetted:

st y,general

rjmp showpcode

setgeneral:

ldi general,0

rjmp generalsetted

 

showpcode:

ldi           control, 0x40|0x80                          ;NOW: 2 lines, 5*7 font, 4-BIT MODE!

rcall        lcdcontrol

ldi zh,high(2*pcode)

ldi zl,low(2*pcode)

ldi general,3

clr yh

ldi yl,$90

ld control,y                                                         ;Read from SRAM

mul control,general

clc

add zl,r0

adc zh,zero

ldi xl,3

back:

lpm general,z+

rcall LCD_write

dec xl

brne back

;finish writing

;********writing subject label**************

ldi zh,high(2*sublabel)

ldi zl,low(2*sublabel)

ldi xl,5

back0:

lpm general,z+

rcall LCD_write

dec xl

brne back0

;**********making of address**********

rcall makeadd

push general                                                      ;save address

;read eeprom

clr yh

mov yl,general

rcall eeprom_read                                           ;code in general

;read subcode

ldi zh,high(2*subcode)

ldi zl,low(2*subcode)

ldi control,3

mul general,control

clc

add zl,r0

adc zh,zero

ldi xl,3

back1:

lpm general,z+

rcall LCD_write

dec xl

brne back1

;writing room label

ldi zh,high(2*lroom)

ldi zl,low(2*lroom)

ldi xl,6

back2:

lpm general,z+

rcall LCD_write

dec xl

brne back2

pop general                                                        ;getting the address back

inc general                                                          ;--> next address

;read room code from eeprom

clr yh

mov yl,general

rcall eeprom_read                                           ;code in general

ldi zh,high(2*room)

ldi zl,low(2*room)

ldi control,3

mul general,control

clc

add zl,r0

adc zh,zero

ldi xl,3

back3:

lpm general,z+

rcall LCD_write

dec xl

brne back3

;time synchronization-not necessary

rcall scroll

;time synchronization-put here

;rcall scroll

;completed 1s

rjmp start

;End of main Program

;#####################################################

;***********address making******************

makeadd:

push yh

clr yh                                                                     ;first clear yh

ldi yl,0x90                                                            ;period on address hex 90

ld general,y

ldi control,2

mul general,control                                        ;necessary result in r0

ldi zh,high(2*daybonus)

ldi zl,low(2*daybonus)

mov general,c_day

clc

add zl,general

adc zh,zero

lpm general,z                                                     ;day bonus found

add general,r0                                                   ;desired address of eeprom in general for sub.

pop yh

ret

;***********************************************

scroll:                                                                    ;function for scrolling

clr yh

ldi yl,0x91

ld general,y

push general

cpi general,21

brlo less20

cpi general,66

brge finishx

rjmp greater20

finishx:

rjmp finish

less20:

ldi control,0x13

sub control,general

ori control,0x80

rcall lcdcontrol

ldi zh,high(2*desig)

ldi zl,high(2*desig)

pop xl

push xl

inc xl

back5:

lpm general,z+

rcall LCD_write

dec xl

brne back5

pop general

inc general

clr yh

ldi yl,$91

st y,general

ret

greater20:

ldi control,$00|$80

rcall lcdcontrol

ldi zh,high(2*desig)

ldi zl,high(2*desig)

pop general

push general

subi general,20

clc

add zl,general

adc zh,zero

ldi xl,20

back6:

lpm general,z+

rcall LCD_write

dec xl

brne back6

pop general

inc general

clr yh

ldi yl,$91

st y,general

ret

finish:

ldi control,$00|$80

rcall lcdcontrol

ldi zh,high(2*desig)

ldi zl,low(2*desig)

pop general

push general

subi general,20

clc

add zl,general

adc zh,zero

ldi general,108

pop control

push control

sub general,control

cpi general,20

brge fixed20

mov xl,general

rjmp back7

fixed20:

ldi xl,20

back7:

lpm general,z+

rcall LCD_write

dec xl

brne back7

pop general

inc general

cpi general,108

breq setcounter

countersetted:

clr yh

ldi yl,$91

st y,general

ret

setcounter:

ldi general,0

rjmp countersetted

;###################################################

eeprom_write:                                                 ;address on y

sbic eecr,eewe                                                 ;data on general register

rjmp eeprom_write

out eearh,yh

out eearl,yl

out eedr,general

sbi eecr,eemwe

sbi eecr,eewe

ret

eeprom_read:                                                  ;data will be get back on general

sbic eecr,eewe

rjmp eeprom_read

out eearh,yh

out eearl,yl

sbi eecr,eere

in general,eedr

ret

;***************function:section***********************

section:

ldi general,$0    

mov howmtimes,general                             ;set howmtimes to zero

mov divideby,general                                    ;set divideby to zero

sectionx:

sub split,divideby                                             ;substract divideby from split

cpi split,$a                                                           ;compare with 10

brlo result                                                           ;branch if less than 10,goto result

add split,divideby                                            ;now add divideby to split

add divideby,ten                                              ;increase divideby value by 10

inc howmtimes                                                 ;increase howmtimes

rjmp sectionx                                                    ;relative jump to sectionx

result:

ldi zh,high(2*digit)                                           ;conver binary to ASCII of seconds

ldi zl,low(2*digit)                                              ;first digit

add zl,howmtimes

adc zh,zero

lpm f_digit,z

ldi zh,high(2*digit)                                           ;conver binary to ASCII of seconds

ldi zl,low(2*digit)                                              ;second digit

add zl,split

adc zh,zero

lpm s_digit,z

ret

;**************end of section function********************

;************LCD delay time*******************************

LCD_delay:                                                         ;2ms delay          takes 1998 cycle

ldi general,0x9d

mov delay1,general

ldi general,0x0c                                                 ;divide by 255

mov delay2,general

loop:

dec delay2

brne loop                                                            ;total 3 cycle

dec delay1

brne loop

ret

;***************end of LCD_delay*************************

;********Tell LCD to work in 4bit mode*******************

lcd_commandbit:                                             ;used for init (we need some 8-bit commands to switch to 4-bit mode!)

ldi general,0b00100000                                  ;10+1998+rcall+ret

out         portd, general

sbi          portd, LCD_E                                      ;now strobe E

                nop

                nop

                nop

cbi          portd, LCD_E

nop

rcall LCD_delay

ret

;***********end of 4bit mode set function****************

;************function for writing LCD********************

LCD_write:

mov rawdata,general

cbr rawdata,0b00001111

sbr rawdata,0b00001000                               ;making RS high for writing

out portd,rawdata

sbi          portd, LCD_E                                      ;now strobe E

                nop

                nop

                nop

cbi          portd, LCD_E

nop

swap general

mov rawdata,general

cbr rawdata,0b00001111

sbr rawdata,0b00001000                               ;making RS high for writing

out portd,rawdata

sbi          portd, LCD_E                                      ;now strobe E

                nop

                nop

                nop

cbi          portd, LCD_E

nop

rcall LCD_delay                                                  ;21+1998+rcall+ret+"ret+rcall"

ret

;**********End of LCD_write Function*********************

;**************LCD_control function**********************

lcdcontrol:

mov rawdata,control

cbr rawdata,0b00001111

out portd,rawdata

sbi          portd, LCD_E                                      ;now strobe E

                nop

                nop

                nop

cbi          portd, LCD_E

nop

swap control

mov rawdata,control

cbr rawdata,0b00001111

out portd,rawdata

sbi          portd, LCD_E                                      ;now strobe E

                nop

                nop

                nop

cbi          portd, LCD_E

nop

rcall LCD_delay                                                  ;20+1998+rcall+ret+"ret+rcall"

ret

;************end lcd control*************************

;**************LCD_initialization function***********

LCD_init:

                rcall        LCD_delay                           ;first, we'll tell the LCD that we want to use it in 4-bit mode.

                rcall        LCD_commandbit            ;LCD is still in 8-BIT MODE while writing this command!!!

                ldi           control, 0x28                      ;NOW: 2 lines, 5*7 font, 4-BIT MODE!

                rcall        lcdcontrol                            ;

                ldi           control, 0x0c                      ;now proceed as usual: Display on, cursor on, blinking

                rcall        lcdcontrol

                ldi           control, 0x01                      ;clear display, cursor -> home

                rcall        lcdcontrol

                ldi           control, 0x06                      ;auto-inc cursor

                rcall        lcdcontrol

ret

;*******************end of LCD_initialization function

l_year:                                                                  ;for leap year

.db 12,16,20,24,28,32,36,40

_m4:                                                                      ;for apr,june,sept,novem.

.db 4,6,9,11

_c_day:                                                                                ;[2.6m-0.2] value for ease

.db 0,7,10,12,15,17,20,23,25,28,30,33,36,0

digit:

.db '0','1','2','3','4','5','6','7','8','9'

_ampm:                                                               ;writing ampm to lcd

.db "AMPM"

_cycle:

.db "Cycle-"

c_dayx:

.db 'A','B','C','D','E','0'

_dayx:

.db "DAY-"

_today:

.db "SUNMONTUEWEDTHUFRISAT0"

_count:

.db 0,$40|$80,$4a|$80,$53|$80,$15|$80,$18|$80,$1b|$80,$1c|$80,$26|$80,$55|$80,$58|$80,$5d|$80,$63|$80,0

credit1:

.db "This Project made by"

credit2:

.db " EEE'06 - A Section "

members1:

.db "Shihab,Tanvir,Shamol"  

members2:

.db "  Pinky and Rushd   "

pcode:

.db "1st2nd3rd4th5th6th7th8th9th "

sublabel:

.db ":EEE- "

daybonus:

.db 0,22,44,66,88,0

subcode:

.db "101102190103104151152200211212221222201213214233234251252253254300311312321322341351352301302313314350361371372381382400461462481482463465466 "

lroom:

.db " ROOM:"

room:

.db "304305306307217MLEMLWECLEMLELLEILPELMTLEWLCMLN/A"

.org $0cff

dseg:

.db "   MD.SOHEL RANA,LECTURER,Dept. of EEE,RUET,MOBILE-01725431631 Email:sohel_ieee@yahoo.com   "

 
Make a Free Website with Yola.