Nds Project Report

  • Uploaded by: Tanvir Hussain
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Nds Project Report as PDF for free.

More details

  • Words: 9,467
  • Pages: 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

iii

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

Table of Contents: Chapter 1 2

Title Introduction Full Design Concept

3 4

5 6 7 8 9

10 11

iv

Page 1

A. Basic Full Circuit Block Diagram B. Block diagram for time and other option synchronization C. Block Diagram for Keyboard Input D. Emergency Power backup

2 2

Full Circuit Schematic Circuit Description A. LCD and its connection B. Diode 1N4007 C. Voltage Regulator 7805 D. Zener Diode E. Relay F. Crystal G. Switch H. 9V Battery I. 9V Battery Connector J. Capacitor Value Calculation K. Maximum Power Consumption L. Weeks day Calculation From Date Printed Circuit Board (PCB) Component list & source Assembler and Simulator Conclusion & Future Scope Appendix A. Datasheet i. ATmega32 ii. DPDT Relay iii. Voltage Regulator 7805 iv. 1N4007 Diode v. LCD B. Full Program C. User Manual

6

Glossary of terms Bibliography

71 72

4 5

8 11 11 11 12 12 12 13 13 13 14 15 16 17 18 19

20 22 23 25 26 27 69

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

v

Page 2 3 4 5 6 7

8 8 11 11 12 12 12 13 13 13 16 16 18 18 69 69

Naïve Digital Synchronizer

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.

1

Naïve Digital Synchronizer

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:

2

Naïve Digital Synchronizer

Figure 1.2: Full program Conceptual Block Diagram

3

Naïve Digital Synchronizer

C. Block Diagram for Keyboard Input:

Figure 2.2: Block diagram for Keyboard input

4

Naïve Digital Synchronizer

D. Emergency Power Backup: .

Figure 2.3: Emergency Power Backup system's block diagram

5

Naïve Digital Synchronizer

6

Chapter-03

Figure 3.1: Full circuit Schematic

Full Circuit Schematic

Naïve Digital Synchronizer

Keyboard Connection:

Figure 3.2: Schematic of Keyboard

7

Naïve Digital Synchronizer

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 complete.

Figure 4.2:20*4 character LCD

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.

8

Naïve Digital Synchronizer

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.

9

Naïve Digital Synchronizer

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

10

Naïve Digital Synchronizer

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

11

Naïve Digital Synchronizer

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.

E. Relay:

Figure 4.5: Zener diode's real picture (Left) and its electrical 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.

12

Naïve Digital Synchronizer

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

13

Naïve Digital Synchronizer

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 2

W = ×C×V2







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 In one month =

1.68×24×30 1000

KW-hour

=1.2096 KW-hour

…(iii)

14

Naïve Digital Synchronizer

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)

Sep 7

Oct 8

Nov 9

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 Code 1

Apr 2

May 3

Jun 4

Jul 5

Aug 6

Dec 10

Jan 11

Feb 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 Code

Sun 0

Mon 1

Tue 2

Wed 3

Thu 4

Fri 5

Sat 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”

15

Naïve Digital Synchronizer

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

16

Naïve Digital Synchronizer

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 MCU-ATmega32 LCD - 20*4 character (Green) 9V Battery 9V Battery connector LM7805 Switches Resistor PCB Crystal Capacitor Diode Nokia Female Connector Relay Wire &miscellaneous Atmega32 Base Grand Total

Source: TELECOM SPARES 36/9, Hossain Market, Patuatuly Dhaka-1100 Website: www.tsparesbd.com Email: [email protected]

HOSSAIN ELECTRONICS S.L. Shopping Plaza, Rani Bazar Rajshahi Mobile-01556312856

Quantity 1 1 1 1 1 6 1KΩ(.25W)-3,100Ω(.5W)-1 6×4”,2×2” 1-4.00MHz 470µF 1N4007-3P,5.6V-ZDiode 1-p 1-p,5V 1-p -

Price 160/= 500/= 60/= 5/= 7/= 10/= 1/= 150/= 8/= 1/= 2/= 3/= 20/= 14/= 20/= 960/=

17

Naïve Digital Synchronizer

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

18

Naïve Digital Synchronizer

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.

19

Naïve Digital Synchronizer

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:

20

Naïve Digital Synchronizer

ii.Datasheet of MR6247:

21

Naïve Digital Synchronizer

22

Naïve Digital Synchronizer

iii.Datasheet of LM7805:

23

Naïve Digital Synchronizer

24

Naïve Digital Synchronizer

atasheet of 1N4007 Diode:

25

Naïve Digital Synchronizer

v.Datasheet of LCD:

26

Naïve Digital Synchronizer

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 . 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

27

Naïve Digital Synchronizer

.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

28

Naïve Digital Synchronizer

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

29

Naïve Digital Synchronizer

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

30

Naïve Digital Synchronizer

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

31

Naïve Digital Synchronizer

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 rcall lcdcontrol ;read eeprom rcall makeadd push yh clr yh mov yl,general push general rcall eeprom_read ldi yl,0x92 st y,general pop general inc general mov yl,general rcall eeprom_read ldi yl,0x93 st y,general pop yh sd: rcall _30ms sbi porta,0 nop in general,pina andi general,$09 cpi general,$09 breq inccountx in general,pina andi general,$11 cpi general,$11 breq deccount in general,pina andi general,$21 cpi general,$21 breq start1x cbi porta,0 nop

;cursor visible and blinking

;address in general ;don't touch yh, never ever!

;save the address ;code in general ;store subcode

;code in general ;store room code ;set/done button check

;checking for left button pressed? ;0000 1001

;checking for right button pressed? ;0001 0001

;checking for done button pressed? ;0010 0001

32

Naïve Digital Synchronizer

sbi porta,1 nop in general,pina andi general,$0a cpi general,$0a breq incment in general,pina andi general,$22 cpi general,$22 breq decment cbi porta,1 nop sbi porta,2 nop in general,pina andi general,$14 cpi general,$14 breq savex cbi porta,2 nop rjmp sd savex: rjmp save start1x: rjmp start1 incment: cpi yh,$15|$80 breq inchour cpi yh,$18|$80 breq incmin cpi yh,$1b|$80 breq incsecond cpi yh,$1c|$80 breq incampm 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

;checking for checking for increament button ;pressed? ;0000 1010 ;checking for decreament button pressed ;0010 0010

;0001 0100

;14

;checking for save button pressed

;the section for increamenting ;is cursor on hour box? ;if yes then jump to inc hour section ;jump to inc min section

;considering the ampm

;inc period

33

Naïve Digital Synchronizer

breq incperiod cpi yh,$4a|$80 breq incsub cpi yh,$53|$80 breq incroom rjmp 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 breq dechour cpi yh,$18|$80 breq decmin cpi yh,$1b|$80 breq decsecond cpi yh,$1c|$80 breq decampm cpi yh,$26|$80 breq deccycle cpi yh,$55|$80 breq decday cpi yh,$58|$80 breq decmonth

;inc subject ;inc room ;if no maches found then jump to sd

;is cursor on hour box? ;if yes then jump to inc hour section ;jump to inc min section

;considering the ampm

34

Naïve Digital Synchronizer

cpi yh,$5d|$80 breq decyearl cpi yh,$63|$80 breq deccday cpi yh,$40|$80 breq decperiod cpi yh,$4a|$80 breq decsub cpi yh,$53|$80 breq decroom rjmp 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: push yh rcall _30ms rcall makeadd mov control,general clr yh ldi yl,0x92 ld general,y mov yl,control rcall eeprom_write

;dec period ;dec subject ;dec room ;if no maches found then jump to sd

;for saving in eeprom ;for debouncing ;will make a address depending on period and day ;address in general ;subcode ;read the subcode from SRAM

35

Naïve Digital Synchronizer

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********************

36

Naïve Digital Synchronizer

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

37

Naïve Digital Synchronizer

;*****************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

38

Naïve Digital Synchronizer

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

39

Naïve Digital Synchronizer

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

40

Naïve Digital Synchronizer

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

41

Naïve Digital Synchronizer

;****************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

42

Naïve Digital Synchronizer

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

43

Naïve Digital Synchronizer

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

44

Naïve Digital Synchronizer

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

45

Naïve Digital Synchronizer

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

46

Naïve Digital Synchronizer

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

47

Naïve Digital Synchronizer

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

48

Naïve Digital Synchronizer

brne npback ldi control, 0x40|$80 rcall lcdcontrol rcall _30ms pop yh rjmp sd

;now moving the cursor to the init position

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:

49

Naïve Digital Synchronizer

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: rcall _30ms

;here we are to jump to start ;delay 30ms for debouncing

50

Naïve Digital Synchronizer

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

51

Naïve Digital Synchronizer

set inc day _hourx: mov general,hour cpi general,0xd brne _day ldi general,0x1 mov hour, general ;stop c_day cbi porta,0 nop sbi porta,1 nop in general,pina andi general,$12 cpi general,$12 brne _xday clt _xday: cbi porta,1 nop sbi porta,0 nop _day: cpi day,29 breq _isfeb cpi day,30 breq _30feb cpi day,31 breq apr cpi day,32 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 _x: lpm general,z+ cp month,general breq month4

;set t flag to indicate day increased ;and increase day

;compare hour to 13

;make low porta.0 ;make high porta.1

;button not pressed ;clear T flag

;now again set porta.0 pin high

;is february? ;in february it will turn to 01 ;is february? ;no, it is not february;check whether it is Apr,June,Sep,Nov? ;no, it is not either

;For loop 4 times

52

Naïve Digital Synchronizer

dec xl tst xl breq _yearl rjmp _x month4: inc month ldi day,0x1 rjmp _yearl _30feb: cpi month,0x2 brne jump inc month ldi day,0x1 jump: rjmp _yearl _isfeb: cpi month,0x2 breq c_lp_year rjmp _yearl not_l_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 xx: lpm general,z+ cp yearl,general breq _yearl dec xl tst xl breq not_l_year rjmp xx _yearl: cpi month,13 brne c_day_calc ldi month,0x1 inc yearl c_day_calc: mov c_month,month cpi c_month,0x3 brlo fejan subi c_month,0x2

;is february ;no it is not then go to yearl ;yes it is february, then inc month ;inc day to 01

;is february? ;if yes, then is leap year? ;not leap year

;For loop 8 times ;load program memory to general ;Yes leap year and branch ;testing xl if it is zero? ;if equal to zero then branch.

;what day it is calcualtion starting.

;select month code

53

Naïve Digital Synchronizer

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 adc zh,zero lpm add r0,day add r0,yearl mov general,yearl lsr general lsr general add r0,general mov general,r0 subi general,40 brmi minus cp general,seven brge plus mov today,general rjmp _bar minus: add general,seven brmi minus mov today,general rjmp _bar plus: sub general,seven cp general,seven brge plus mov today,general rjmp _bar _bar: mov c_month,month cpi c_month,0x3 brlo _fejan rjmp _now _fejan: inc yearl _now: brtc LCD_show

;increamenting z pointer as c_month ;load program memory ;[2.6m-0.2]+d+c ;[2.6m-0.2]+d+y+c

;divide by 4 of yearl ;[2.6m-0.2]+d+y+[y/4]+c ;[2.6m-0.2]+d+y+[y/4]+c+[c/4]-40, c=20 ;if result is minus then branch ;branch if greater than six ;if inbetween 0-6 then direct jump to bar calc.

;now it is not minus

;compare between seven and general ;branch if general>=seven

;select month code

;Moving day to today

54

Naïve Digital Synchronizer

cpi general,0x5 brlo x_bar clt rjmp LCD_show x_bar: clt inc c_day cpi c_day,0x5 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 rcall section mov general,f_digit rcall LCD_write mov general,s_digit rcall LCD_write ldi general,':' rcall LCD_write mov split,min rcall section mov general,f_digit rcall LCD_write mov general,s_digit rcall LCD_write ldi general,':' rcall LCD_write mov split,second rcall section mov general,f_digit rcall LCD_write mov general,s_digit rcall LCD_write ldi zh,high(2*_ampm) ldi zl,low(2*_ampm) mov general,ampm cpi general,0x0 ldi xl,0x2

;day is Friday or saturday? ;not above days then inc cycle day

;clear T flag ;is c_day equal to five means to F not E?

;split hour ;write to LCD

;split minute ;write to LCD

;split second ;write to LCD

;Writhing to lcd the am or pm

55

Naïve Digital Synchronizer

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

56

Naïve Digital Synchronizer

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

57

Naïve Digital Synchronizer

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

58

Naïve Digital Synchronizer

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+

59

Naïve Digital Synchronizer

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 inc general ;read room code from eeprom clr yh mov yl,general rcall eeprom_read 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

;getting the address back ;--> next address

;code in general

60

Naïve Digital Synchronizer

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

61

Naïve Digital Synchronizer

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)

62

Naïve Digital Synchronizer

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

63

Naïve Digital Synchronizer

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

64

Naïve Digital Synchronizer

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 4bit 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

65

Naïve Digital Synchronizer

nop nop portd, LCD_E

cbi 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.

66

Naïve Digital Synchronizer

rcall ldi rcall ldi rcall ldi rcall ldi rcall

LCD_commandbit control, 0x28 lcdcontrol control, 0x0c lcdcontrol control, 0x01 lcdcontrol control, 0x06 lcdcontrol

;LCD is still in 8-BIT MODE while writing this command!!! ;NOW: 4 lines, 5*7 font, 4-BIT MODE! ; ;now proceed as usual: Display on, cursor not blinking ;also not visitble ;clear display, cursor -> home ;auto-inc cursor

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- "

67

Naïve Digital Synchronizer

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:[email protected] " ;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

68

Naïve Digital Synchronizer

69

Appendix-C User Manual NDS Familiarization:

Subject Code Period no. Time Date

Scrolling designation Room no. 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

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. 2. 3. 4. 5.

Press the Set/Done Button Cursor will be visible Press  or  button to move the cursor to second/minute/hour position Press ↓ or ↑ button to decrease or increase time 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. 2. 3. 4. 5.

Change the C_Day as desired Change the period as shown above Change Room no. Cange Subject 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.

70

Naïve Digital Synchronizer

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.

71

Naïve Digital Synchronizer

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.pdfcoke.com/doc/11057004/AVR-assembly-Examples [4]. Instruction set Nomenclature Source: www.atmel.com [5]. The art of Assembly Source: www.pdfcoke.com [6]. My Experience in Programming AVR By-Bibin John

Internet Links: [1]. www.pdfcoke.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

72

Related Documents

Nds Project Report
May 2020 5
1219-nds
November 2019 22
Nds Games
June 2020 9
Project Report
May 2020 2
Project Report
June 2020 2

More Documents from ""

Nds Project Report
May 2020 5
List Of 74xxx And 4xxx Ic
December 2019 16
Avr Assembly Examples
December 2019 14
Software Usb
December 2019 8