Смекни!
smekni.com

Особенности разработки микропроцессорной системы и устройства для чтения электронных книг (стр. 11 из 13)

ldi work, 0x55

mov address0,work

mov address1,work

clr address2

sbrc flag,1

sbr address2,0x08;если стирается вторая флешь

ldi data,0xaa

rcall adr_latch

ldi work, 0xaa

mov address0,work

ldi work, 0x2a

mov address1,work

ldi data,0x55

rcall adr_latch

ldi work, 0x55

mov address0,work

mov address1,work

ldi data,0x80

rcall adr_latch

ldi work, 0x55

mov address0,work

mov address1,work

ldi data,0xaa

rcall adr_latch

ldi work, 0xaa

mov address0,work

ldi work, 0x2a

mov address1,work

ldi data,0x55

rcall adr_latch

ldi work, 0x55

mov address0,work

mov address1,work

ldi data,0x10

rcall adr_latch

sbi portd,WE

pop work

mov store,work

ldi work,10

wait_10s:;память стирается 10 секунд. Максимум, правда.

rcall wait_1s

dec work

brne wait_10s

mov work,store

sbi portd,WE

ret

;-----------------------------------------------------------------------

read_flash:

sbi portd,WE

cbi portd,OE

push work

clr work

out ddrb,work

rcall adr_latch

ser work

out ddrb,work

pop work

sbi portd,OE

ret

;-----------------------------------------------------------------------

write_flash:

mov store,address0

mov storel,address1

mov storeh,address2

cbi portd,WE

sbi portd,OE

push work

ldi work, 0x55

mov address0,work

mov address1,work

cbr address2,0xf7;если пишется во вторую флешь

ldi data,0xaa

rcall adr_latch

ldi work, 0xaa

mov address0,work

ldi work, 0x2a

mov address1,work

ldi data,0x55

rcall adr_latch

ldi work, 0x55

mov address0,work

mov address1,work

ldi data,0xa0

rcall adr_latch

mov address0,store

mov address1,storel

mov address2,storeh

mov data,char

rcall adr_latch

push char

rcall data_polling

pop char

pop work

sbi portd,WE

ret

;-----------------------------------------------------------------------

wait_1s:

push work

ldi work,0x47

pause_1s_l:

rcall pause

dec work

brne pause_1s_l

pop work

ret

;-----------------------------------------------------------------------

module_write:

clr work

clr book

clr address0

clr address1

clr address2

find_empty_slot:

rcall read_flash

cpi data,0x5e

brne empty_slot

rcall inc_addr

inc book

mov work,book

cpi work,0x08

brne find_empty_slot

ldi hiz,(high(no_slot*2))

ldi loz,(low(no_slot*2))

rcall message

rcall push_button

ret

empty_slot:

ldi char,0x5e

rcall write_flash

ldi hiz,(high(type_header*2))

ldi loz,(low(type_header*2))

rcall message

clr address2

clr address1

ldi address0,0x0b;смещение=8 + адрес=3

mov work,book

sbrc work,0

sbr address0,0x40

sbrc work,1

sbr address0,0x80

sbrc work,2

sbr address1,0x01

ldi work,55

ret_enter_name:

sbis usr,rxc

rjmp ret_enter_name

rcall RXcomplete

rcall write_flash

rcall inc_addr

dec work

breq stop_write_header

cpi char,0x07

brne ret_enter_name

rjmp type_status_reciev

stop_write_header:

ldi char,0x07

rcall write_flash

type_status_reciev:

ldi hiz,(high(reciev_file*2))

ldi loz,(low(reciev_file*2))

rcall message

rcall get_address_text_begin

module_write_cont:

sbis usr,rxc

rjmp module_write_cont

rcall RXcomplete

cpi char,0x07

breq ret_module_write

mov data,char

rcall write_flash

rcall confirm

rcall inc_addr

sbrs flag,0;если память переполнена.

rjmp module_write_cont

ldi hiz,(high(memory_full*2))

ldi loz,(low(memory_full*2))

rcall message

rcall push_button

ret

ret_module_write:

mov char,address2

mov storead1,address1

mov storead0,address0

clr address2

clr address1

ldi address0,0x08

mov work,book

sbrc work,0

sbr address0,0x40

sbrc work,1

sbr address0,0x80

sbrc work,2

sbr address1,0x01

rcall write_flash

rcall inc_addr

mov char,storead1

rcall write_flash

rcall inc_addr

mov char,storead0

rcall write_flash

ldi hiz,(high(file_recieved*2))

ldi loz,(low(file_recieved*2))

rcall message

ret

;-----------------------------------------------------------------------

module_read:

ПРИЛОЖЕНИЕ А (Продолжение)

;clr address0

;clr address1

;clr address2

show_to_screen:

rcall read_flash

mov rus,data

mov char,data

rcall write_char

rcall inc_addr

cpi count,TSYM-1

breq branch

rjmp show_to_screen

branch:

rcall push_button

cpi key,1

breq ret_module_read

cpi key,2

breq show_to_screen

minus_tsym:

subi address0,low(TSYM*2)

sbci address1,high(TSYM*2)

brsh show_to_screen

dec address2

brpl show_to_screen

clr address0

clr address1

clr address2

rjmp show_to_screen

ret_module_read:

ret

;-----------------------------------------------------------------------

module_erase:

clr work;Вначале стираются закладки в ЭППЗУ

clr count

out eearh,work

rcall wait_write_internal_eeprom

ldi work,0x01

erase_bookmark:

out eearl,work

ser data

out eedr,data

rcall write_internal_eeprom

rcall wait_write_internal_eeprom

subi work,0xfc

inc count

cpi count,8

brne erase_bookmark

ldi hiz,(high(memory_erased_process*2))

ldi loz,(low(memory_erased_process*2))

rcall message

rcall erase_flash

ldi hiz,(high(memory_erased*2))

ldi loz,(low(memory_erased*2))

rcall message

ret

;-----------------------------------------------------------------------

;Нажатие кнопки. Возвращаемый код: 1-красная кнопка, 2-зелёная вниз, 3-зелёная вверх

push_button_no_wait:

push work

clr key

sbis pina,5

rjmp red

sbis pina,6

rjmp green_down

sbis pina,7

rjmp green_up;ЭЄю рэрыюушўэыщ єўрёЄюъ ъюфр,

ret;Єюы№ъю схч юцшфрэш эрцрЄш ъэюяъш

push_button:

;ret

push work

clr key

wait_push_button:

clr work

sbis pina,5

rjmp red

sbis pina,6

rjmp green_down

sbis pina,7

rjmp green_up

rjmp wait_push_button;ЗрЎшъыхэю: эрцрЄ№ яЁшфёЄё

red:

dec work

nop

breq pull_red

sbis pina,5

rjmp red

rjmp wait_push_button

clr_pull_red:

clr work

pull_red:

dec work

nop

breq red_quit

sbic pina,5

rjmp pull_red

rjmp clr_pull_red

red_quit:

pop work

ldi key,1

ret

green_down:

dec work

nop

breq pull_green_down

sbis pina,6

rjmp green_down

rjmp wait_push_button

clr_pull_green_down:

clr work

pull_green_down:

dec work

nop

breq green_down_quit

sbic pina,6

rjmp pull_green_down

rjmp clr_pull_green_down

green_down_quit:

pop work

ldi key,2

ret

green_up:

dec work

nop

breq pull_green_up

sbis pina,7

rjmp green_up

rjmp wait_push_button

clr_pull_green_up:

clr work

pull_green_up:

dec work

nop

breq green_up_quit

sbic pina,7

rjmp pull_green_up

rjmp clr_pull_green_up

green_up_quit:

pop work

ldi key,3

ret

;-----------------------------------------------------------------------

blank_screen:

ser count

ldi char, 0b00000001

rcall write_cmd

ret

;-----------------------------------------------------------------------

message:

;ret

push work

sbr flag,0x08

rcall blank_screen

message_loop:

lpm

mov work,rsym

cpi work,0x0

breq go_away

cpi work,0x1

brne no_return

ldi char, 0b11000000

rcall write_cmd

rjmp message_adr_inc

no_return:

mov char,work

push loz

push hiz

rcall write_data

pop hiz

pop loz

message_adr_inc:

inc loz

brne message_loop

inc hiz

rjmp message_loop

go_away:

sbrc flag,3

pop work

cbr flag,0x08

ret

;Выводимые сообщения. AVR Studio некорректно понимает коды русских симолов, так что пришлось извратиться.

hello:

.db ' ',bS,_i,_s,_t,_e,_m,_a,' ',' ','"',bK,_n,_i,_g,_o,_ch,_e,_j,'"',0x01,' ',bV,_e,_r,_s,_i,_ya,' ','1','.','3','7',0x00

begin:

.db ' ',bN,_a,_ch,_a,_t,_q,' ',_ch,_i,_t,_a,_t,_q,' ',_k,_n,_i,_g,_u,0x01,0x00

ret_cursor:

.db 0x7e,0x00

zakladka:

.db ' ',bD,_o,_s,_t,_a,_t,_q,' ',_z,_a,_k,_l,_a,_d,_k,_u,0x01,0x00

about:

.db ' ',bR,_e,_a,_l,_i,_z,_o,_v,_a,_n,_o,'.','.','.',0x0

about_develop:

.db ' ','R','&','D',' ','7','-',_ya,' ',bZ,_a,_s,_t,_a,_v,_a,'.',' ',bS,_o,_z,_d,_a,_l,' ','S','e','a','G','u','l','l','.',0x01,' ',bE,_s,_l,_i,' ',_ch,_t,_o,',',' ',_p,_i,_sh,_i,_t,_e,' ',_n,_a,' ','"','s','e','a','g','u','l','l','@','m','a','i','l','.','r','u','"',0x00

computer:

.db ' ',bS,_v,_ya,_z,_a,_t,_q,_s,_ya,' ',_s,' ',bEE,bV,bM,0x01,0x00

i_love_my_computer:

.db ' ',bZH,_d,_u,' ',_s,_v,_ya,_z,_i,' ',_n,_a,' ','1','1','5','2','0','0',0x01,' ',bP,_o,_d,_k,_l,_yu,_ch,_i,_t,_e,' ',_p,_o,_r,_t,'.',0x00

continue:

.db ' ',bP,_r,_o,_d,_o,_l,_zh,_i,_t,_q,' ',_ch,_i,_t,_a,_t,_q,0x01,0x00

pop_zakl:

.db ' ',bP,_o,_l,_o,_zh,_i,_t,_q,' ',_z,_a,_k,_l,_a,_d,_k,_u,0x01,0x00

high_inc:

.db ' ',bL,_i,_s,_t,_a,_t,_q,0x01,0x00

memory_erased:

.db ' ',bP,_a,_m,_ya,_t,_q,' ',_s,_t,_yo,_r,_t,_a,'!',0x00

list_kb:

.db ' ',bV,_v,_e,_d,_i,_t,_e,' ',_sh,_a,_g,' ',_p,_r,_o,_l,_i,_s,_t,_y,_v,_a,_n,_i,_ya,0x01,' ','(',_v,' ',_t,_y,_s,_ya,_ch,_a,_h,' ',_s,_i,_m,_v,_o,_l,_o,_v,')',':',0x00

address_set:

.db ' ',bA,_d,_r,_e,_s,' ',_v,_y,_s,_t,_a,_v,_l,_e,_n,0x00

memory_erased_process:

.db ' ',bS,_t,_i,_r,_a,_yu,'.','.','.',0x00

reciev_file:

.db ' ',bP,_r,_i,_yo,_m,' ',_i,_n,_f,_o,_r,_m,_a,_ts,_i,_i,0x00

file_recieved:

.db ' ',bI,_n,_f,_o,_r,_m,_a,_ts,_i,_ya,' ',_p,_r,_i,_n,_ya,_t,_a,'!',0x00

no_text:

.db ' ',bK,_n,_i,_g,_i,' ',_n,_e,' ',_b,_y,_l,_i,' ',_z,_a,_p,_i,_s,_a,_n,_y,'!',0x00

no_slot:

.db ' ',bN,_e,_t,' ',_m,_e,_s,_t,_a,' ',_v,' ',_t,_a,_b,_l,_i,_ts,_e,' ',_p,_o,_d,' ',_k,_n,_i,_g,_u,'!',0x01,' ',bK,_n,_i,_g,' ',_n,_e,' ',_b,_o,_l,_q,_sh,_e,' ','8','-',_m,_i,'!',0x00

type_header:

.db ' ',bV,_s,_t,_u,_ch,_i,_t,_e,' ',_z,_a,_g,_o,_l,_O,_v,_o,_k,'.',0x00

memory_full:

.db ' ',bP,_a,_m,_ya,_t,_q,' ',_z,_a,_p,_o,_l,_n,_e,_n,_a,' ',_p,_o,_l,_n,_o,_s,_t,_q,_yu,'!',0x00

no_bookmark:

.db ' ',bZ,_a,_k,_l,_a,_d,_k,_a,' ',_d,_l,_ya,' ',_ee,_t,_o,_j,' ',_k,_n,_i,_g,_i,' ',_o,_t,_s,_u,_t,_s,_t,_v,_u,_e,_t,'!',0x00

;-----------------------------------------------------------------------

menu:

;ret

clr count

choose_menu:

sbrs flag,2

rjmp current

ring_menu:

push count

rcall blank_screen

pop count

cpi count,2

breq start_pos_1

cpi count,3

breq start_pos_2

start_pos_0:

cpi count,0

brne end_pos_01

rcall show_cur

rjmp end_pos_02

end_pos_01:

rcall show_space

end_pos_02:

ldi hiz,(high(begin*2))

ldi loz,(low(begin*2))

rcall message_loop

start_pos_1:

cpi count,1

brne end_pos_11

rcall show_cur

rjmp end_pos_12

end_pos_11:

rcall show_space

end_pos_12:

ldi hiz,(high(zakladka*2))

ldi loz,(low(zakladka*2))

rcall message_loop

cpi count,2

brlo polling

start_pos_2:

cpi count,2

brne end_pos_21

rcall show_cur

rjmp end_pos_22

end_pos_21:

rcall show_space

end_pos_22:

ldi hiz,(high(computer*2))

ldi loz,(low(computer*2))

rcall message_loop

cpi count,2

breq polling

start_pos_3:

cpi count,3

brne end_pos_31

rcall show_cur

rjmp end_pos_32

end_pos_31:

rcall show_space

end_pos_32:

ldi hiz,(high(about*2))

ldi loz,(low(about*2))

rcall message_loop

polling:

rcall push_button

cpi key,2

breq add_count

cpi key,3

breq sub_count

ret

add_count:

cpi count,3

breq choose_menu

inc count

rjmp choose_menu

sub_count:

cpi count,0

breq choose_menu

dec count

rjmp choose_menu

;Меню, вылазиющее при чтении

current:

push count

rcall blank_screen

pop count

cpi count,2

breq start_cur_1

cpi count,3

breq start_cur_2

start_cur_0:

cpi count,0

brne end_cur_01

rcall show_cur

rjmp end_cur_02

end_cur_01:

rcall show_space

end_cur_02:

ldi hiz,(high(continue*2))

ldi loz,(low(continue*2))

rcall message_loop

start_cur_1:

cpi count,1

brne end_cur_11

rcall show_cur

rjmp end_cur_12

end_cur_11:

rcall show_space

end_cur_12:

ldi hiz,(high(zakladka*2))

ldi loz,(low(zakladka*2))

rcall message_loop

cpi count,2

brlo polling

start_cur_2:

cpi count,2

brne end_cur_21

rcall show_cur

rjmp end_cur_22

end_cur_21:

rcall show_space

end_cur_22:

ldi hiz,(high(pop_zakl*2))

ldi loz,(low(pop_zakl*2))

rcall message_loop

cpi count,2

breq polling

start_cur_3:

cpi count,3

brne end_cur_31

rcall show_cur

rjmp end_cur_32

end_cur_31:

rcall show_space

end_cur_32:

ldi hiz,(high(high_inc*2))

ldi loz,(low(high_inc*2))

rcall message_loop

rjmp polling

show_cur:

ldi hiz,(high(ret_cursor*2))

ldi loz,(low(ret_cursor*2))

rcall message_loop

ret

show_space:

ldi char,' '

rcall write_data

ret

;-----------------------------------------------------------------------

listing:

push work

rcall blank_screen

ldi count,1

ldi hiz,(high(list_kb*2))

ldi loz,(low(list_kb*2))

rcall message_loop

select_kbyte:

ldi char, 0b11010111

rcall write_cmd

cpi count,0x0a

brsh big_gid

mov work,count

rcall dec_itoa

ldi char,' '

rcall write_data

rjmp after_show

big_gid:

ldi char,'1'

push count

rcall write_data

pop count

ldi char, 0b11011000

rcall write_cmd

mov work,count

subi work,0x0a

rcall dec_itoa

after_show:

rcall push_button

cpi key,3

breq inc_kbyte

cpi key,2

breq dec_kbyte

pop work

ret

inc_kbyte:

cpi count,16

breq select_kbyte

inc count

rjmp select_kbyte

dec_kbyte:

cpi count,1

breq select_kbyte

dec count

rjmp select_kbyte

dec_itoa:

ldi char,0x30