Вы находитесь на странице: 1из 78

Project Report on Naïve Digital Synchronizer

Project Completed by Group-4


S.M. Al Muhid Shihab-061041
Tanvir Hussain Bappi-061049
MD. Nura Alam Shamol-061050
Ashrafun Naher Pinky-061051
Ahmad Rushd-061052

Project Supervised by:


MD. Sohel Rana, Lecturer, Dept. of EEE, RUET

Rajshahi University of Engineering and Technology(RUET)


Kajla, Rajshahi, Bangladesh
Abstract:

In this report we described about Naïve Digital Synchronizer (NDS) a dedicated device made
for keeping track of time, date, weeks day, cycle of our RUET’s academic routine, Day of the
cycle, and whole electrical department routine. It also scrolls right to left the name,
designation, mobile number and email address of our project supervisor MD. Sohel Rana,
Lecturer, Dept. of EEE, RUET. We also described about user manual of this device and its part by
part description.

i
Acknowledgement
We the group-4, MD. Al Muhid Shihab, Tanvir Hussain, Nura Alam Shamol, Ashrafun Naher
Pinky and Ahmad Rushd gratefully acknowledge the guidance provided by the project
supervisor MD. Sohel Rana, Lecturer, Dept. of EEE, RUET throughout the development of the
project.

We also thank MD. Syduzzaman Shahin, EEE-061058 and Sheikh Alauddin, IPE for providing
various encouragement, help and support during the development of the project.

ii
Candidate’s Declaration:

We hereby declare that this project report titled “Naïve Digital Synchronizer (NDS)” submitted towards
the completion of 5th semester Electronic Shop Practice Course no. EEE-300 of B.Sc. Eng. in Rajshahi
University of Engineering and Technology (RUET) is an academic record of our work carried under
Lecturer MD. Sohel Rana, Dept. of EEE, RUET.

Date: 05.07.09
Place: Kajla, Rajshahi, Bangladesh.

X X
S.M Al Muhid Shihab, EEE'06-061041 Tanvir Hussain Bappi,EEE'06-061049

X X
MD. Nura Alam, EEE'06-061050 Ashrafun Naher Pinky, EEE'06-061051

X
Ahmad Rushd, EEE'06-061052

Certificate:
This is to certify that the above declaration made by S.M. Al Muhid Shihab, Tanvir Hussain Bappi, MD.
Nura Alam , Ashrafun Naher Pinky and Ahmad Rushd is true to the best of my knowledge and belief.

Date:
Place: Kajla, Rajshahi, Bangladesh
X
MD. Sohel Rana
Lecturer,Dept. of EEE, RUET

iii
Table of Contents:
Chapter Title Page
1 Introduction 1
2 Full Design Concept

A. Basic Full Circuit Block Diagram 2


B. Block diagram for time and other 2
option synchronization
C. Block Diagram for Keyboard Input 4
D. Emergency Power backup 5

3 Full Circuit Schematic 6


Circuit Description
4 A. LCD and its connection 8
B. Diode 1N4007 11
C. Voltage Regulator 7805 11
D. Zener Diode 11
E. Relay 12
F. Crystal 12
G. Switch 12
H. 9V Battery 13
I. 9V Battery Connector 13
J. Capacitor Value Calculation 13
K. Maximum Power Consumption 14
L. Weeks day Calculation From Date 15
5 Printed Circuit Board (PCB) 16
6 Component list & source 17
7 Assembler and Simulator 18
8 Conclusion & Future Scope 19
9 Appendix
A. Datasheet
i. ATmega32 20
ii. DPDT Relay 22
iii. Voltage Regulator 7805 23
iv. 1N4007 Diode 25
v. LCD 26
B. Full Program 27
C. User Manual 69

10 Glossary of terms 71
11 Bibliography 72

iv
List of Figures:
Name of the Figure Page
Figure 2.1: Basic Full circuit block diagram of NDS 2
Figure 1.2: Full program Conceptual Block Diagram 3
Figure 2.2: Block diagram for Keyboard input 4
Figure 2.3: Emergency Power Backup system's block diagram 5
Figure 3.1: Full circuit Schematic 6
Figure 3.2: Schematic of Keyboard 7
Figure 4.1: Power Backup Circuit Schematic 8
Figure 4.2: 20*4 character LCD 8
Figure 4.3: Diode Real Picture(Right) and its electrical symbol (Left) 11
Figure 4.4: Voltage Regulator 7805 11
Figure 4.5: Zener diode's real picture (Left) and its electrical symbol (Right) 12
Figure 4.6: Relay internal Connection and its real picture 12
Figure 4.7: Crystal's real picture (Left) and its electrical symbol (Right) 12
Figure 4.8: Switch 13
Figure 4.9: 9V Battery 13
Figure 4.10: 9V Battery Connector 13
Figure 5.1: PCB Design of main Circuit Board from opposite to soldering side 16
Figure 5.2: PCB Design of Keyboard from opposite to soldering side 16
Figure 7.1: AVR Studio Processor for Microcontroller 18
Figure 7.2: AVR Studio 4 Starting, Selecting the Assembler 18
Figure 9.1: NDS Display Familiarization 69
Figure 9.2: Keyboard Familiarization 69

v
Naïve Digital Synchronizer 1

Chapter-01
Introduction

In RUET we know that the routine is exclusively followed by different procedure i.e. the cycle day
method. Sometimes it becomes difficult specially after vacation to locate the cycle-day. So we
invented a device which will synchronize our whole RUET’s Academic Routine and time. This device
will show time, date, weeks day, Cycle day, and Cycle no. It also will show the Routine and the name,
designation, mobile no. and email address of the person who owns the device. The name of this
device is Naive digital Synchronizer. “Naïve” because it is the first version of this device as well as
the firmware also at initial stage. “Digital” because everything here are computed and done digitally
and “Synchronizer” because it synchronizes our whole RUET’s academic routine as well as time. For
the completion for our project we are using microcontroller ATmega32. Because using this, the
circuit complexity will reduce to a great minimum level. For the development of our firmware for
ATmega32 we used assembly language. Because everyone knows that for any time critical firmware
it is the best solution to use assembly language. The top engineers of renowned company also
prescribe this. The program written in assembly language runs faster, takes less space than same
program written in other language. How strong your compiler is, it does not matter, no other
programming language can write strong and efficient program as assembly language, whether it is
avr-gcc, betterfly-c, image craft or bascom. For display purpose we used 20×4 character LCD because
it is compact display and saves power. For input we used matrix keyboard. Here we also have
emergency power backup system.

Our experience says that what we are going to do will take much space in flash memory. So we must
have to use such a microcontroller which has large Flash memory. For this reason we used
ATmega32 which has 32KB flash momory.
Naïve Digital Synchronizer 2

Chapter-02
Full Design Concept

A. Basic Full circuit block diagram:

Figure 2.1: Basic Full circuit block diagram of NDS

B. Block Diagram for time and other option synchronization:


Naïve Digital Synchronizer 3

Figure 1.2: Full program Conceptual Block Diagram


Naïve Digital Synchronizer 4

C. Block Diagram for Keyboard Input:

Figure 2.2: Block diagram for Keyboard input


Naïve Digital Synchronizer 5

D. Emergency Power Backup:


.

Figure 2.3: Emergency Power Backup system's block diagram


Naïve Digital Synchronizer 6

Chapter-03
Full Circuit Schematic

Figure 3.1: Full circuit Schematic


Naïve Digital Synchronizer 7

Keyboard Connection:

Figure 3.2: Schematic of Keyboard


Naïve Digital Synchronizer 8

Chapter-04
Circuit Description

Figure 4.1: Power Backup Circuit Schematic

A. LCD:
To activate LCD, to write anything on it we must have to first initialize it. For this purpose we have to
send some control command to
the LCD, which includes telling the
LCD about what font size, no. of
lines, cursor will be visible or not,
blinking or underscore, shift the
display or not, work in 8bit mode
or 4bit mode etc. the LCD control
command are given below:

The LCD Command Set:

Most of the LCD commands don't


need more time for the LCD to
execute them than writing a
character. The datasheet of the
LCD used for writing this code
stated 40µs for a simple
command.

Clear Display: 0x01


This command clears the display
and returns the cursor to the
home position (line 0, column 0).
This command takes 1.64 ms to Figure 4.2:20*4 character LCD
complete.

Cursor Home: 0b0000001x


This commands also sets the cursor position to zero, but the display data remains unchanged. It also
takes 1.64 ms for execution, but it also shifts the display to its original position.
Naïve Digital Synchronizer 9

Entry Mode:

0 0 0 0 0 1 I/D S

I/D: Increment/Decrement Cursor bit. If set, the cursor will be post-incremented after any read data
or write data operation. If cleared, the cursor will be post-decremented.

S: If set, the whole display will be shifted, depeding on I/D: If I/D and S are set, the display will be
shifted to the left, if I/D is cleared (S set), the display will be shifted to the right. Usually I/D = 1, S = 0
is used (increment cursor, don't shift display).

Display On/Off:

0 0 0 0 1 D C B

D: Display On/Off. If set, the display is turned on. When the display is turned off, character data
remains unchanged.

C: Cursor On/Off. If set, the cursor is visible in the way set by B.

B: Cursor blink on/off. If this bit is set, the cursor will blink as a black block. Otherwise the cursor is
shown as an underscore _.

Shift Cursor/Display:

0 0 0 1 S/C R/L x x

S/C: If set, the display is shifted. If cleared, the cursor is shifted. The direction depends on R/L.

R/L: If set, the display/cursor is shifted to the right. If cleared, it's shifted to the left.

Function Set:

0 0 1 DL N F x x

DL: Interface length. If set, 8-bit mode is selected (as in this example). If cleared, 4 bit mode is
selected.

N: Number of display lines. If cleared, the LCD is a one line display. If set, the display is in 2/4 line
mode.

F: Font size. If cleared, 5x7 Font is selected. If set, 5x10 font is selected.

CG Ram Address Set:

0 1 ACG

ACG is the Address to be set for Character Generator Ram access. The CG can be used to configure
and show custom characters.
Naïve Digital Synchronizer 10

DD Ram Address Set:

1 ADD

ADD is the address to be set for Display Data Ram access. The display data ram holds the data
displayed (the characters). See below for DD Ram organisation.

Busy Flag/DD Ram Address READ:

BF ADD

If the command register is read, the value actually returned by the LCD is the DD Ram Address (bits
0..6) and the busy flag (bit 7). THe busy flag should be read after every command to achieve max
speed. If the busy flag is set, the controller is still busy executing a command/writig data.

Display Data Addressing:

The display controller has to offer a way of addressing all display characters which works for ALL
kinds of displays. That's why the rows don't follow each other. The rows start at fixed addresses:

Display size 1st row 2nd row 3rd row 4th row
Nx8 $00 - $07 $40 - $47 x x
N x 16 $00 - $0F $40 - $4F $10 - $1F $50 - $5F
N x 20 $00 - $13 $40 - $53 $14 - $27 $54 - $67
Of course this list is not complete, but it shows some mean details about using a 16 x 4 display: The
first address of the second row is bigger than the first address of the third row!

Example: For setting the cursor to the 3rd character of the second row in a 16 x 2 display, write 0x42
| 0b10000000 to the display command register.

LCD connection:

LCD Other terminal

D7 -- -- D7 of m32

D6 -- -- D6 of m32

D5 -- -- D5 of m32

D4 -- -- D4 of m32

RS -- -- D3 of m32

R/W -- -- Gnd

VDD -- -- +5V

V0 -- -- Gnd
Naïve Digital Synchronizer 11

Vss -- -- Gnd

LED+ -- -- +5V

LED- -- -- Gnd

E -- -- D2 of m32

B. Diode-1N4007:

Figure 4.3:Diode Real Picture(Right) and its electrical symbol(Left)

The 1N4007 diode here is being used for prevent any reverse current comes from point B to A when
main power is off (Figure 4.1) and B to C when Backup power is off(Figure 4.2). Here maximum
reverse voltage is 5V and the 1N4007 has capability of preventing reverse voltage of about 1000V.

C. Voltage Regulator LM7805:


The voltage regulator 7805 is used to make 9V to 5V converter
here. As the datasheet of 7805 says that it must have to have
a voltage greater than 7.2V for stable 5V output and here our
input is 9V, so we will get 5V output from the 7805 IC. As our
input is DC, so we did not use any capacitor on input and
output.

Figure 4.4:Voltage Regulator 7805


Naïve Digital Synchronizer 12

D. Zener Diode:
Here the zener diode we used
for protection purpose, so that if
the input voltage rises more that
5.6V it will be clipped at this
level. As a result our device will
not damage for over voltage.
Figure 4.5: Zener diode's real picture (Left) and its electrical
E. Relay: symbol (Right)

Here we used 5V relay. When current flows


through A to B (Figure 4.6) 1 and 5, 2 and 6 is
short circuited. When relay is off 3 and 5,6 and
4 is short circuited. We used this property
when main power is on, a current flows
through A to B (Figure 4.6) and Relay is in
open position for our circuit as 1 and 5 is short

circuit, but in our schematic we used Figure 4.6: Relay internal Connection and its real
connection 3 and 5. At this time no voltage picture
comes to the input point of voltage regulator 7805 IC. When main power is off 3 and 5 is short
circuited and 9V battery finds a path to supply to the input of 7805 IC.

F. Crystal:

Figure 4.7:Crystal's real picture (Left) and its electrical symbol (Right)

Here we used a 4.00MHz crystal for more specific time, and it is connected to the ATmega32 to the
pin 11 and 12, XTAL1 and XTAL2.
Naïve Digital Synchronizer 13

G. Switch:

Figure 4.8: Switch

Here we are using push to make switch as in any keyboard this type of switch is used. This switch
short circuits when it is pushed and open circuited when it is released. We also used two Stay put
switch for stopping the Cycle’s Day, for controlling main power supply and for controlling the power
supply from battery.

H. 9V Battery:
In our project to maintain the time when main power goes off we are using a
9V battery. A nine-volt battery, sometimes referred to as a PP3 battery, is
shaped as a rounded rectangular prism and has a nominal output of nine
volts. Its nominal dimensions are 48 mm × 25 mm × 15 mm (ANSI standard
1604A). In this type of battery normally no Ah rating is written, so we can’t

say how long this battery will last. Figure 4.9: 9V Battery

I. 9V Battery connector:

Figure 4.10: 9V Battery Connector

To connect the battery to the main circuit we are using a 9V battery connector.

J. Capacitor Value canculation:


The datasheet of the Relay says that it will take about 3ms to switch the relay. We also know the
diode 1N4007 and Voltage Regulator IC 7805 will take some time to switch. In total though it will be
Naïve Digital Synchronizer 14

not more than 4ms For safety we will take here 10ms that we need backup to reach power from
battery to main power point B. (Figure 4.1)

Here we need maximum about 5V and 300mA Current.

So total Power, P= V×I

P=5×.3

P=1.5Watt … … … … (i)

Energy, W = Pt

W = 1.5 × 10ms

W = 0.015 Joule … … … … (ii)

This power must come from a capacitor. We know energy stored in capacitor is
1
W = ×C×V2 … … … …(iii)
2

Equating equation (ii) and equation (iii) we get


1
0.015=2×C×V2

Here we know Voltage, V = 5


1
So, 0.015 = 2×C×52

Or, C = 200µF

For safety, we will use 470µF capacitor.

K. Maximum Power Consumption of NDS:


Maximum Voltage, V = 5.6V

Maximum Current, I = 300mA

Power, P = V×I

P = 5.6×.3

P = 1.68 Watt
1.68×24×30
In one month = KW-hour
1000

=1.2096 KW-hour
Naïve Digital Synchronizer 15

Finding Out the Weeks Day From Date:


To find out weeks day from a given date we used the following formula

A = [2.6×M-.2]+D+Y+[Y/4]+[C/4]-2C … … …(iv)

Here,

M = number of month
D = number of Date
C = 1st two digits of a year
Y = last two digits of a year

Here [ ] always indicates integer part.

Code of Month:

Month Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb
Code 1 2 3 4 5 6 7 8 9 10 11 12

After putting all values we will get a value of A.

Now, A%7 = ? , The remainder is consisting the required day.

Code of Day:

Day Sun Mon Tue Wed Thu Fri Sat


Code 0 1 2 3 4 5 6

It has to be note that for January and February We have to calcutate using the previous year that is if
the year is 2000 then we have to calculate using year 1999.

If A becomes negative then we have to add 7 to A until it becomes positive.

Example:

24th Nov 1975

Here,
D = 24
M =9
C =19
Y =75
A = [2.6×9-0.2]+24+75+[75/4]+[19/4]-(2×19)
= 23+24+75+18+4-38=106
Code = A%7 = 1; threrefor “Monday”
Naïve Digital Synchronizer 16

Chapter-05
Printed Circuit Board (PCB)

Figure 5.1: PCB Design of main Circuit Board from opposite to soldering side

Figure 5.2: PCB Desing of Keyboard from opposite to soldering side


Naïve Digital Synchronizer 17

Chapter-06
Component List and Sources

In this project we used various kinds of parts. Below we are giving a table containing details cost of
this project. As we are using MCU so our circuit has reduced to so much easy. Though the circuit has
reduced the complexity of the program has increased. So the cost has also reduced at a great
amazing level.

Table 6.1: Component list and its price

Component name Quantity Price


MCU-ATmega32 1 160/=
LCD - 20*4 character (Green) 1 500/=
9V Battery 1 60/=
9V Battery connector 1 5/=
LM7805 1 7/=
Switches 6 10/=
Resistor 1KΩ(.25W)-3,100Ω(.5W)-1 1/=
PCB 6×4”,2×2” 150/=
Crystal 1-4.00MHz 8/=
Capacitor 470µF 1/=
Diode 1N4007-3P,5.6V-ZDiode 2/=
Nokia Female Connector 1-p 3/=
Relay 1-p,5V 20/=
Wire &miscellaneous - 14/=
Atmega32 Base 1-p 20/=
Grand Total - 960/=

Source:
TELECOM SPARES
36/9, Hossain Market, Patuatuly
Dhaka-1100
Website: www.tsparesbd.com
Email: humayun_ts@yahoo.com

HOSSAIN ELECTRONICS
S.L. Shopping Plaza, Rani Bazar
Rajshahi
Mobile-01556312856
Naïve Digital Synchronizer 18

Chapter-07
Assembler and Simulator

As assembler and simulator here we used AVR-Studio. After Writing the program we debugged it,
assembled it and everything has been done with this software then we simulated this program on
this software. As downloader to download hex file we used stk200 programmer and bascom.

Figure 7.1: AVR Studio Processor for


Microcontroller

Figure 7.2: AVR Studio 4 Starting, Selecting the Assembler


Naïve Digital Synchronizer 19

Chapter-08
Conclusion and Future Scope

This project can be further enriched by adding here a rechargeable battery power backup system
instead of fixed battery. More Application can be added in this project such as Alarm Clock, Sound,
Stop watch and many other things, in that case bigger character LCD or Graphic LCD must be used.
The whole academic calendar and other vacation of RUET can be included here. If here a more
advanced keyboard and program are used then any kind of massage, mobile no. email address as
well as any kind of information such as Result or CGPA can be saved here in the EEPROM of the
microcontroller. Further Research Can be done to reduce power consumption.
Naïve Digital Synchronizer 20

Appendix-A
Datasheet

In the upcoming some pages datasheet of ATmega32,Voltage regulator IC 7805, Relay, Diode
1N4007 and are given from original source without any modification.

i. Datasheet of ATmega32:
Naïve Digital Synchronizer 21

ii.Datasheet of MR6247:
Naïve Digital Synchronizer 22
Naïve Digital Synchronizer 23

iii.Datasheet of LM7805:
Naïve Digital Synchronizer 24
Naïve Digital Synchronizer 25

atasheet of 1N4007 Diode:


Naïve Digital Synchronizer 26

v.Datasheet of LCD:
Naïve Digital Synchronizer 27

Appendix-B
Full Program

;***********************************************************
;* Project Name:Naive Digital Synchronizer (NDS) *
;* 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 *
;* Al Muhid Shihab, Tanvir Hussain, Nura Alam, Ashrafun Naher *
;* Ahamad Rushd *
;* Rajshahi University of Engineering and Technology(RUET) *
;* EEE’06-A section *
;***********************************************************
; 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/>.
; N.B. Comment is not well described.
;
;latest update of this program can be found on “the-xenox.yolasite.com”
;***********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
Naïve Digital Synchronizer 28

.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 11:59: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
Naïve Digital Synchronizer 29

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
Naïve Digital Synchronizer 30

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
Naïve Digital Synchronizer 31

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:
;200ms
ldi control,100
mor:
rcall LCD_delay
dec control
brne mor
nop
ret ;completes here
inccountx:
rjmp inccount
set_done:
rcall _30ms
Naïve Digital Synchronizer 32

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
Naïve Digital Synchronizer 33

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
Naïve Digital Synchronizer 34

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
Naïve Digital Synchronizer 35

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
Naïve Digital Synchronizer 36

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
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********************
Naïve Digital Synchronizer 37

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
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
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
Naïve Digital Synchronizer 38

;*****************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
rcall LCD_write
Naïve Digital Synchronizer 39

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
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
Naïve Digital Synchronizer 40

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
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
Naïve Digital Synchronizer 41

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
Naïve Digital Synchronizer 42

;****************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
Naïve Digital Synchronizer 43

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
rcall LCD_write
Naïve Digital Synchronizer 44

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
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
Naïve Digital Synchronizer 45

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
Naïve Digital Synchronizer 46

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
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
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
Naïve Digital Synchronizer 47

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
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
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
Naïve Digital Synchronizer 48

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
Naïve Digital Synchronizer 49

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:
Naïve Digital Synchronizer 50

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
Naïve Digital Synchronizer 51

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 Program.
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
Naïve Digital Synchronizer 52

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
Naïve Digital Synchronizer 53

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
Naïve Digital Synchronizer 54

rjmp calculate
fejan:
add c_month,ten
dec yearl
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:
mov c_month,month
cpi c_month,0x3
brlo _fejan ;select month code
rjmp _now
_fejan:
inc yearl
_now:
brtc LCD_show ;Moving day to today
Naïve Digital Synchronizer 55

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
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
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
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
Naïve Digital Synchronizer 56

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
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
rcall LCD_write
Naïve Digital Synchronizer 57

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
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
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
Naïve Digital Synchronizer 58

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
Naïve Digital Synchronizer 59

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+
Naïve Digital Synchronizer 60

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
ldi xl,5
ag1:
rcall LCD_delay
dec xl
brne ag1
ldi general,0xff
mov delay1,general
mov delay1,general
ldi xl,8
floop:
dec delay1
Naïve Digital Synchronizer 61

brne floop
dec delay2
brne floop
dec xl
brne floop
rcall scroll
;exact timing
rcall LCD_delay
rcall LCD_delay
ldi xl,4
ldi general,133
mov delay1,general
exact:
dec delay1
brne exact
dec xl
brne exact
;time synchronization-put here
ldi general,0xff
mov delay1,general
mov delay1,general
ldi xl,8
sloop:
dec delay1
brne sloop
dec delay2
brne sloop
dec xl
brne sloop
;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
Naïve Digital Synchronizer 62

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,low(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,low(2*desig)
Naïve Digital Synchronizer 63

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
Naïve Digital Synchronizer 64

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
Naïve Digital Synchronizer 65

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 8000 cycle
ldi general,0x0b
mov delay1,general
ldi general,0x60 ;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
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
Naïve Digital Synchronizer 66

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
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
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.
Naïve Digital Synchronizer 67

rcall LCD_commandbit ;LCD is still in 8-BIT MODE while writing this command!!!
ldi control, 0x28 ;NOW: 4 lines, 5*7 font, 4-BIT MODE!
rcall lcdcontrol ;
ldi control, 0x0c ;now proceed as usual: Display on, cursor not blinking
rcall lcdcontrol ;also not visitble
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- "
Naïve Digital Synchronizer 68

daybonus:
.db 0,22,44,66,88,0
subcode:
.db
"10110219010310415115220021121222122220121321423323425125225325430031131232132234
1351352301302313314350361371372381382400461462481482463465466 "
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 "

;eeprom image
.eseg ;initial value of routine is set to zero
A:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
B:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
C:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
D:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
E:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Naïve Digital Synchronizer 69

Appendix-C
User Manual

NDS Familiarization:

Subject Code
Scrolling designation
Period no.
Time Room no.
Date Cycle no.
Weeks Day

Cycle Day name

Save in EEPROM
Move Cursor Right
Increase Value
Set/Done
Move Cursor Left
Stop C_day Counting Decrease Value

Figure 9.1:NDS Display Familiariation

Keyboard Familiarization:

Figure 9.2: Keyboard familiarization


Naïve Digital Synchronizer 70

In this keyboard in total we have 8 button. But here we are using 7 button and one is reserved for
future use and compatibility. For any change first we have to press the Set/Done button. The key 
and  is used for moving the Cursor on LCD left or Right. ↑ and ↓is used for increasing or
decreasing value where the cursor lies. If in vacation we want to stop the Cycle Day counting then
we have to press ones the Stop C_Day button. To Save Routine we have to press the Save button.
After Completion we have to press Set/Done button again.

How to Change Time:

1. Press the Set/Done Button


2. Cursor will be visible
3. Press  or  button to move the cursor to second/minute/hour position
4. Press ↓ or ↑ button to decrease or increase time
5. When done Press Set/Done button.

Changing Date, C_Day, Cycle are same as above.

Changing the Weeks Day:

It is not Applicable. As the NDS will automatically findout the Day by its own algorithm.

Stopping the C_Day:

We just have to press the Stop C_Day button to stop the C_day before vacation. After coming back
from vacation we will have to release the button again pressiang it. But here you have to increase it
manually one day to update yourself with routine.

Changing the Routine:

1. Change the C_Day as desired


2. Change the period as shown above
3. Change Room no.
4. Cange Subject
5. Press Save button

Saving the Routine:

1. Change the Routine as desired with the C_day and Cycle


2. Press Save button
3. A massage on LCD #Done# will be shown to inform you that it is saved.

N/A:

If no period is going to held then the set the room no. to N/A position. This will indicate that no class
is going to held at that time.
Naïve Digital Synchronizer 71

Chapter-10
Glossary of Terms

MCU - Microcontroller Unit

C_day - Cycle Day that is A, B, C, D or E day of a cycle.

Simulation - A computer simulation (or "sim") is an attempt to model a real-life or hypothetical


situation on a computer so that it can be studied to see how the system works. By changing
variables, predictions may be made about the behaviour of the system.

http://en.wikipedia.org/wiki/Simulation

Hex file - Intel HEX is a file format for conveying binary information for applications like
programming microcontrollers, EPROMs, and other kinds of chips. It is one of the oldest file
formats available for this purpose, having been in use since the 1970s.

The format is a text file, with each line containing hexadecimal values encoding a sequence
of data and their starting offset or absolute address.

http://en.wikipedia.org/wiki/.hex

Ah - Ampere Hour Rating of a battery.

STK200 - The STK200 Flash MCU Starter Kit is a complete low-cost evaluation system for the Atmel’s
8-bit FLASH microcontrollers made by AVR technology.
Naïve Digital Synchronizer 72

Chapter-11
Bibliography

Books:

[1]. Begineers Introduction to AVR-Assembly


By-Gerhard Schmidt
[2]. AVR-An Introductory Course.
By-John Morton
[3].AVR example complete
Source: http://www.scribd.com/doc/11057004/AVR-assembly-Examples
[4]. Instruction set Nomenclature
Source: www.atmel.com
[5]. The art of Assembly
Source: www.scribd.com
[6]. My Experience in Programming AVR
By-Bibin John

Internet Links:

[1]. www.scribd.com
[2]. www.atmel.com
[3]. www.avr-asm-tutorial.net/avr-en/
[4]. www.alldatasheet.com
[5]. www.datasheetcatalog.com
[6]. www.avrfreaks.net
[7]. http://attiny.com/
[8]. http://avr-asm.tripod.com/
[9]. http://www.avr-asm-download.de/
[10]. http://www.avrbeginners.net/
[11]. http://www.aimscientific.com/products/projects.htm

Вам также может понравиться