;Memos database selected so put it on screen and check for button push mdbmenu: clr cursorow ldi ZL,low(memos) ;load memos start address ldi ZH,high(memos) rcall dispmemo ;display first memo info ldi wreg,0b00001110 ;display cursor rcall lcdcmd ldi wreg,0x80 rcall lcdcmd ldi temp,1 ;keep track of which memo # we're on mov tempsave,temp mdblp: sbic PINB,6 ;check left button rjmp mdbbut7 ;if not pushed check 2nd button ldi wreg,64 rcall debounce ;if pushed debounce it tst flag breq mdblp ;if not proper push, continue looping ldi timeout,2 ;get 2 iterations in loop ldi temp,1 cp tempsave,temp breq mwbut6 dec tempsave mdbflp: ldi XL,low(memos) ;check to make sure not at first contact yet ldi XH,high(memos) cp XL,ZL cpc XH,ZH breq mdbendc sbiw ZL,1 ;go back 2 memo terminators and forward ld wreg,Z ; by one char for memo before current one cpi wreg,0x03 brne mdbflp dec timeout brne mdbflp ;once back 2 memo terminators adiw ZL,1 ;move forward to first character of contact mdbendc:rcall dispmemo ;display the contact ldi wreg,0x80 rcall lcdcmd mwbut6: sbis PINB,6 rjmp mwbut6 rjmp mdblp ;continue checking buttons mdbbut7:sbic PINB,7 ;check right button rjmp mdbbut1 ;if not pushed loop again ldi wreg,128 rcall debounce ;if pushed debounce it tst flag breq mdblp ;if not proper push, continue looping cp tempsave,mdbcount breq mdblp ;if already at rightmost memo keep looping inc tempsave adiw ZL,1 ;move forward to first character of memo rcall dispmemo ;display the memo ldi wreg,0x80 rcall lcdcmd mwbut7: sbis PINB,7 rjmp mwbut7 rjmp mdblp ;continue checking buttons mdbbut1:sbic PINB,1 ;check add button rjmp mdbbut2 ;if not pushed loop again ldi wreg,2 rcall debounce ;if pushed debounce it tst flag breq mdblp ;if not proper push, continue looping ldi wreg,memolimit ;limit the number of memos to 2 to fit in 8535 SRAM cp mdbcount,wreg breq mdbbut2 ;so if we're at the limit don't allow another addition inc mdbcount ;there's now another contact mwbut1: sbis PINB,1 ;wait for button release rjmp mwbut1 rcall mdbadd ;add new blank memo rjmp mdbmenu ;display the new blank first memo mdbbut2:sbic PINB,2 ;check delete button rjmp mdbbut3 ;if not pushed loop again ldi wreg,4 rcall debounce ;if pushed debounce it tst flag breq mdbbut3 ;if not proper push, continue looping dec mdbcount mwbut2: sbis PINB,2 rjmp mwbut2 rcall mdbdel ldi temp,0 cp mdbcount,temp breq mnoconts rjmp mdbmenu ;there are memos remaining so display the first one mnoconts:ldi wreg,0b00001100 rcall lcdcmd rjmp cmmenu ;return to cmmenu because there's nothing to display mdbbut3:sbic PINB,3 ;check to see if the user wants to edit the current line rjmp mdbbut4 ldi wreg,16 rcall debounce ;debounce tst flag breq mdbret mwbut3: sbis PINB,3 ;wait for button to be released rjmp mwbut3 rcall mdbedit ;call subroutine mdbret: rjmp mdblp mdbbut4:sbic PINB,4 ;check to see if the user wants to move up one row rjmp mdbbut5 ldi wreg,32 rcall debounce ;debounce tst flag breq mdblp1 mwbut4: sbis PINB,4 ;wait for button to be released rjmp mwbut4 cpi cursorow,0 ;determine the current row breq mrow41 cpi cursorow,1 breq mrow42 cpi cursorow,2 breq mrow43 ldi wreg,0x94 ;if on row 4 move to row 3 rcall lcdcmd dec cursorow mdblp1: rjmp mdblp mrow41: rjmp mdblp ;if on row 1 do nothing mrow42: dec cursorow ;if on row 2 move to row 1 ldi wreg,0x80 rcall lcdcmd rjmp mdblp mrow43: dec cursorow ;if on row 3 move to row 2 ldi wreg,0xC0 rcall lcdcmd rjmp mdblp mdbbut5:sbic PINB,5 ;check to see if the user wants to move down one row rjmp mdbbut0 ldi wreg,64 rcall debounce ;debounce tst flag breq mdblp1 mwbut5: sbis PINB,5 ;wait for button to be released rjmp mwbut5 cpi cursorow,0 ;determine the current row breq mrow51 cpi cursorow,1 breq mrow52 cpi cursorow,2 breq mrow53 ;if on row 4 do nothing rjmp mdblp mrow51: inc cursorow ;if on row 1 move to row 2 ldi wreg,0xC0 rcall lcdcmd rjmp mdblp mrow52: inc cursorow ;if on row 2 move to row 3 ldi wreg,0x94 rcall lcdcmd rjmp mdblp mrow53: inc cursorow ;if on row 3 move to row 4 ldi wreg,0xD4 rcall lcdcmd rjmp mdblp mdbbut0:sbic PINB,0 ;check to see if the user is ready to exit to the rjmp mdblp ;previous menu ldi wreg,1 rcall debounce ;debounce tst flag breq mdblp1 mwbut0: sbis PINB,0 ;wait for button to be released rjmp mwbut0 rjmp cmmenu ; return to previous menu ;displays 4 lines of memo information at the addr passed in on Z dispmemo: ldi YL,low(row1) ;load addr for first display row ldi YH,high(row1) mdbr1: ld wreg,Z ;load in character adiw ZL,1 cpi wreg,0x03 ;check for end of current memo breq mdbr1 ;if not keep going cpi wreg,0x01 ;check for end of memo data breq mdbfin cpi wreg,0x02 ;check for end of current field breq mdb2 ;check for end of current line data st Y,wreg ;store data in RAM to be displayed adiw YL,1 rjmp mdbr1 mdb2: ldi temp,12 ;fill the last 12 chars with spaces ldi wreg,0x20 ;load 0x20 for space storing mdbr1clr:st Y,wreg ;store space adiw YL,1 dec temp brne mdbr1clr ;keep looping for 12 iterations ldi temp,0x00 ;store terminating 0x00 st Y,temp ldi YL,low(row2) ;load addr for 2nd display row ldi YH,high(row2) mdbr2: ld wreg,Z ;load in character adiw ZL,1 cpi wreg,0x03 ;check for end of current memo breq mdbr2 ;if not keep going cpi wreg,0x01 ;check for end of memo data breq mdbfin cpi wreg,0x02 ;check for end of current field breq mdb3 st Y,wreg ;store data in RAM to be displayed adiw YL,1 rjmp mdbr2 mdb3: ldi temp,0x00 ;store terminating 0x00 st Y,temp ldi YL,low(row3) ;load addr for 3rd display row ldi YH,high(row3) mdbr3: ld wreg,Z ;load in character adiw ZL,1 cpi wreg,0x03 ;check for end of current memo breq mdbr3 ;if not keep going cpi wreg,0x01 ;check for end of memo data breq mdbfin cpi wreg,0x02 ;check for end of current field breq mdb4 st Y,wreg ;store data in RAM to be displayed adiw YL,1 rjmp mdbr3 mdb4: ldi temp,0x00 ;store terminating 0x00 st Y,temp ldi YL,low(row4) ;load addr for 4th display row ldi YH,high(row4) mdbr4: ld wreg,Z ;load in character adiw ZL,1 cpi wreg,0x03 ;check for end of current memo breq mdbr4 ;if not keep going cpi wreg,0x01 ;check for end of memo data breq mdbfin1 cpi wreg,0x02 ;check for end of current field breq mdbfin1 ;check for end of current line data st Y,wreg ;store data in RAM to be displayed adiw YL,1 rjmp mdbr4 mdbfin1:ldi temp,0x00 ;store terminating 0x00 st Y,temp mdbfin: rcall print4lines ;this writes back the data altered in edit mode from the display RAM to db RAM mdbback:ldi XL,low(memos) ;catch the case where it's the first memo ldi XH,high(memos) cp ZL,XL cpc ZH,XH breq mdcont sbiw ZL,1 ;move back to last contact ld temp,Z cpi temp,0x03 ;by checking for terminator string brne mdbback adiw ZL,1 ;then move forward one to start of string mdcont: ldi YL,low(row1) ;set up pointer to rows ldi YH,high(row1) ldi timeout,8 ;copy date from row to memo db RAM mdbdtlp:ld temp,Y ;load data from display row adiw YL,1 ;prepare for next character st Z+,temp ;store data to contact dec timeout brne mdbdtlp ;repeat until first name done ldi temp,0x02 ;add field terminator st Z+,temp ldi timeout,20 ;now copy memo1 ldi YL,low(row2) ;set up pointer to row ldi YH,high(row2) mdbmem1:ld temp,Y adiw YL,1 ;prepare for next character st Z+,temp ;store data to contact dec timeout brne mdbmem1 ;repeat until memo1 done ldi temp,0x02 ;add field terminator st Z+,temp ldi timeout,20 ;now copy memo2 ldi YL,low(row3) ;set up pointer to row ldi YH,high(row3) mdbmem2:ld temp,Y adiw YL,1 ;prepare for next character st Z+,temp ;store data to contact dec timeout brne mdbmem2 ;repeat until memo2 done ldi temp,0x02 ;add field terminator st Z+,temp ldi timeout,20 ;now copy phone number ldi YL,low(row4) ;set up pointer to row ldi YH,high(row4) mdbmem3:ld temp,Y adiw YL,1 ;prepare for next character st Z+,temp ;store data to contact dec timeout brne mdbmem3 ;repeat until phone number is done ldi temp,0x02 ;add field terminator st Z+,temp ldi temp,0x03 ;add contact terminator st Z,temp ret ;this will delete the current memo in view by moving ; all of the memo after it back one contact mdbdel: ldi XL,low(memos);catch the case where it's the first contact ldi XH,high(memos) mdbdel2:cp ZL,XL cpc ZH,XH breq mdbdel1 ;we're at the beginning sbiw ZL,1 ;move back to last memo ld temp,Z cpi temp,0x03 ;by checking for terminator string brne mdbdel2 adiw ZL,1 ;then move forward one to start of string mov XL,ZL mov XH,ZH mdbdel1: adiw XL,50 ;move X out one memo ahead of Z adiw XL,23 ld temp,X ;check whether we're at last memo in list cpi temp,0x01 brne mdbmvlp ;if not proceed normally st Z,temp ;otherwise store the 0x01 to mark the end of the list and leave ret mdbmvlp:ld temp,X ;copy each character from next memo to this one st Z,temp adiw ZL,1 ;increment each one to copy next character adiw XL,1 ld temp,X cpi temp,0x01 ;end copying at memo db terminator brne mdbmvlp st Z,temp ret ;this will add a memo entry to the beginning of the list (Java takes ; care of the sorting later when they're written back) ; it is done by moving each memo forward by one entry then taking ; the entered data and placing in the new slot at the front of the list mdbadd: ldi YL,low(memos);Y marks first slot in list ldi YH,high(memos) ld temp,Z cpi temp,0x01 brne mdbad1 mov XL,YL mov XH,YH adiw ZL,50 ;move Z one contact forward of X adiw ZL,22 st Z+,temp rjmp mskipempty mdbad1: ld temp,Z ;first we must find end of list cpi temp,0x01 breq mdbago ;loop until reaching list terminator adiw ZL,1 rjmp mdbad1 mdbago: mov XL,ZL ;set X to Z position mov XH,ZH sbiw XL,1 ;move back to end of last memo adiw ZL,50 ;move Z one memo forward of X adiw ZL,23 ldi temp,0x01 ;place terminator at end of list again st Z,temp sbiw ZL,1 ldi YL,low(memos) ;Y marks first slot in list ldi YH,high(memos) ld temp,X ;store the 0x03 terminator first then run through st Z,temp ; all characters until reaching the very beginning mdbalp: sbiw ZL,1 ;move on to the next character sbiw XL,1 ld temp,X ;move the character if not st Z,temp cp XL,YL ;check to see if at beginning of list yet cpc XH,YH brne mdbalp ;if so we're done creating a memo slot mskipempty: ldi temp,0x20 ;now load the space character and blank out mov tempsave,temp ; all of the characters in the new slot ldi temp,0x02 ; while sticking in the proper line terminators of 0x02 ldi timeout,8 ;run through 8 characters first which is the date mdbadat:st X,tempsave ;store the " " character adiw XL,1 ;move to next character slot dec timeout brne mdbadat ;loop for 8 character slots st X,temp ;store the 0x02 terminator adiw XL,1 ldi timeout,20 ;run through 20 characters for memo line 1 mdbalin1:st X,tempsave ;store the " " character adiw XL,1 ;move to next character slot dec timeout brne mdbalin1 ;loop for 20 character slots st X,temp ;store string terminator of 0x02 adiw XL,1 ldi timeout,20 ;run through 20 characters for memo line 2 mdbalin2:st X,tempsave ;store the " " character adiw XL,1 ;move to next character slot dec timeout brne mdbalin2 ;loop for 20 character slots st X,temp ;store string terminator of 0x02 adiw XL,1 ldi timeout,20 ;run through 20 characters for memo line 3 mdbalin3:st X,tempsave ;store the " " character adiw XL,1 ;move to next character slot dec timeout brne mdbalin3 ;loop for 20 character slots st X,temp ;store string terminator of 0x02 adiw XL,1 ldi temp,0x03 st X,temp ;store string terminator of 0x03 ldi ZL,low(memos) ;move Z to first memos char to ldi ZH,high(memos) ; prepare for new blank memo display rcall dispmemo ret ;this allows you to edit the current line selected and ; it writes the data back from display RAM to db RAM on exit mdbedit:cpi cursorow,3 ;determine the current row breq mnextrow4 cpi cursorow,2 breq mnextrow3 cpi cursorow,1 breq mnextrow2 ldi XL,low(row1) ;if we are on row 1 load row1 ldi XH,high(row1) ldi wreg,7 ;set line limit ot 8 for date rjmp mcontrow mnextrow2: ldi XL,low(row2) ;if we are on row 2 then load row 2 ldi XH,high(row2) ldi wreg,19 ;set line limit to 20 characters rjmp mcontrow mnextrow3: ldi XL,low(row3) ;if we are on row 3 then load row3 ldi XH,high(row3) ldi wreg,19 ;set line limit to 20 characters rjmp mcontrow mnextrow4: ldi XL,low(row4) ;if we are on row 4 then load row4 ldi XH,high(row4) ldi wreg,19 ;set line limit to 20 characters rjmp mcontrow mcontrow: mov YL,XL ;load pointers for Editchar mov YH,XH rcall Editchar ;call subroutine ;pin3 gets you into editing and after pin0 enter you come back here clr wreg rcall mdbback ldi wreg,0b00001110 ;display cursor rcall lcdcmd ldi wreg,0x80 rcall lcdcmd ret