; thrust stand data ac system ;Read the comments in "8535def.inc" .include "8535def.inc" ; def files for all chips are in an app note on the CD rom and web page ;***** Subroutine Register Variables ******** .def spi =r16 .def temp =r17 .def uart =r18 .def adc1_l =r19 .def adc1_h =r20 .def adc2_l =r21 .def adc2_h =r22 .def adc3_l =r23 .def adc3_h =r23 .def adc4_l =r24 .def adc4_h =r24 .def temp2 =r25 .equ adc1 =0x60 ;2 bytes adc1+1 is msb .equ adc2 =0x62 ;2 bytes .equ adc3 =0x64 ;2 bytes .equ adc4 =0x66 ;2 bytes .equ eecounter =0x68 ;1 byte .equ eeram =0x70 ;128 bytes ;********* Start Up ************************* .org 0x00 ; first place in code space (page 4-25) rjmp startup ; first command is to jump to start .org 0x10 startup: ldi r16, high(RAMEND) out sph, r16 ; Init stack pointer (page 4-11) ldi r16, low(RAMEND) out spl, r16 ; Init stack pointer ldi r16, 0xfe ; set for 1 for output and 0 for input out ddra, r16 ; data direction registor for port B ; See page 4-61 in data book ldi r16, 0x00 ; set for 1 for output and 0 for input out ddrb, r16 ; data direction registor for port B ; See page 4-61 in data book ldi r16, 0xff ; set for 1 for output and 0 for input out ddrc, r16 ; data direction registor for port B ; See page 4-61 in data book ldi r16, 0xf0 ; set for 1 for output and 0 for input out ddrd, r16 ; data direction registor for port B ; See page 4-61 in data book ldi temp, 0x18 ;init uart pg 5-53 out UCR,temp ; ldi temp,23 ;Set Uart speed to 9600 pg 5-56 out UBRR,temp ;rcall config_ad rcall config_relays ;*********Operation code begins here********* Begin: ;rcall red rcall command ;rcall delayx ;rcall mainmenu ;rcall Spisetup ;rcall EE_wren ;rcall EE_wrsr ;rcall EE_RDSR ;mov uart,spi ;rcall phex ;rcall newline ;rcall read_a2d ;mov uart,adc1_h ;rcall phex ;ldi uart,' ' ;rcall cout ;mov uart,adc1_l ;rcall phex ;rcall newline ;rcall green ;rcall delayx rjmp begin ;********* Command Prompt ************************* Command: ldi ZL, low(msg_prompt) ldi ZH, high(msg_prompt) rcall pstr comm1: rcall cin rcall cout mov temp,uart cpi temp,'a' breq comm2 cpi temp,'A' breq comm2 cpi temp,'r' breq r cpi temp,'g' breq g rcall comm_error ret r: rcall red ret g: rcall green ret comm2: rcall cin ;got 'a' rcall cout mov temp,uart cpi temp,'t' breq comm3 cpi temp,'T' breq comm3 rcall comm_error ret comm3: rcall cin ;got 't' rcall cout mov temp,uart cpi temp,' ' breq comm3 cpi temp,13 breq comm_OKx ;begin adding first letter of commands here. cpi temp,'0' breq comm_offx cpi temp,'1' breq comm_on cpi temp,'S' breq comm_s cpi temp,'s' breq comm_s rjmp comm_error ret comm_offx: rjmp comm_off comm_OKx: rjmp comm_ok comm_on: rcall cin rcall cout mov temp,uart cpi temp,'r' breq on_rx cpi temp,'R' breq on_rx cpi temp,'s' breq on_sx cpi temp,'S' breq on_sx cpi temp,'i' breq on_ix cpi temp,'I' breq on_ix cpi temp,'a' breq on_ax cpi temp,'A' breq on_ax cpi temp,'t' breq on_tx cpi temp,'T' breq on_tx rjmp comm_error on_rx: rjmp on_r on_sx: rjmp on_s on_ix: rjmp on_i on_ax: rjmp on_a on_tx: rjmp on_t comm_s: rcall cin rcall cout mov temp,uart cpi temp,'T' breq comm_st cpi temp,'t' breq comm_st rjmp comm_error ret comm_st: rcall cin rcall cout mov temp,uart cpi temp,'A' breq comm_sta cpi temp,'a' breq comm_sta rjmp comm_error ret comm_sta: rcall newline ldi ZL, low(msg_status) ldi ZH, high(msg_status) rcall pstr ldi uart,' ' rcall cout sbic pina,0 ;Rocket Ready rcall comm_1 ;if this is called rcoket read is high sbis pina,0 rcall comm_0 sbic portc,2 ;rolleron rcall comm_1 ; sbis portc,2 rcall comm_0 sbic portc,3 ;strobe rcall comm_1 ; sbis portc,3 rcall comm_0 sbic portc,1 ;siren rcall comm_1 ; sbis portc,1 rcall comm_0 sbic porta,1 ;t-5 rcall comm_1 ; sbis porta,1 rcall comm_0 sbic portc,0 ;ignightor rcall comm_1 ; sbis portc,0 rcall comm_0 sbic portc,4 ;aux1 rcall comm_1 ; sbis portc,4 rcall comm_0 sbic portc,5 ;aux2 rcall comm_1 ; sbis portc,5 rcall comm_0 sbic portc,6 ;aux3 rcall comm_1 ; sbis portc,6 rcall comm_0 sbic portc,7 ;aux4 rcall comm_1 ; sbis portc,7 rcall comm_0 rcall newline ret comm_1: ldi uart,'1' rcall cout ret comm_0: ldi uart,'0' rcall cout ret comm_OK: rcall newline ldi ZL, low(msg_ok) ldi ZH, high(msg_ok) rcall pstr ;rcall newline ret comm_Error: rcall newline ldi ZL, low(msg_Error) ldi ZH, high(msg_Error) rcall pstr rcall newline ret comm_off: rcall cin rcall cout mov temp,uart cpi temp,'r' breq off_rx cpi temp,'R' breq off_rx cpi temp,'s' breq off_sx cpi temp,'S' breq off_sx cpi temp,'i' breq off_ix cpi temp,'I' breq off_ix cpi temp,'a' breq off_ax cpi temp,'A' breq off_ax cpi temp,'t' breq off_tx cpi temp,'T' breq off_tx rjmp comm_error off_rx: rjmp off_r off_sx: rjmp off_s off_ix: rjmp off_i off_ax: rjmp off_a off_tx: rjmp off_t off_a: rcall cin rcall cout mov temp,uart cpi temp,'1' breq aux1_offx cpi temp,'2' breq aux2_offx cpi temp,'3' breq aux3_offx cpi temp,'4' breq aux4_offx rjmp comm_error aux1_offx: rjmp aux1_off aux2_offx: rjmp aux2_off aux3_offx: rjmp aux3_off aux4_offx: rjmp aux4_off on_a: rcall cin rcall cout mov temp,uart cpi temp,'1' breq aux1_onx cpi temp,'2' breq aux2_onx cpi temp,'3' breq aux3_onx cpi temp,'4' breq aux4_onx rjmp comm_error aux1_onx: rjmp aux1_on aux2_onx: rjmp aux2_on aux3_onx: rjmp aux3_on aux4_onx: rjmp aux4_on off_t: rcall cin rcall cout mov temp,uart cpi temp,'5' breq t5_offx rjmp comm_error t5_offx: rjmp t5_off on_t: rcall cin rcall cout mov temp,uart cpi temp,'5' breq t5_onx rjmp comm_error t5_onx: rjmp t5_on on_r: rcall cin rcall cout mov temp,uart cpi temp,'o' breq roll_onx cpi temp,'O' breq roll_onx rjmp comm_error roll_onx: rjmp roll_on off_r: rcall cin rcall cout mov temp,uart cpi temp,'o' breq roll_offx cpi temp,'O' breq roll_offx rjmp comm_error roll_offx: rjmp roll_off on_i: rcall cin rcall cout mov temp,uart cpi temp,'g' breq ignitor_on cpi temp,'G' breq ignitor_on rjmp comm_error off_i: rcall cin rcall cout mov temp,uart cpi temp,'g' breq ignitor_off cpi temp,'G' breq ignitor_off rjmp comm_error off_s: rcall cin rcall cout mov temp,uart cpi temp,'i' breq siren_off cpi temp,'I' breq siren_off cpi temp,'t' breq strobe_off cpi temp,'T' breq strobe_off rjmp comm_error on_s: rcall cin rcall cout mov temp,uart cpi temp,'i' breq siren_on cpi temp,'I' breq siren_on cpi temp,'t' breq strobe_on cpi temp,'T' breq strobe_on rjmp comm_error strobe_on: rcall comm_ok ldi ZL, low(msg_strobe_on) ldi ZH, high(msg_strobe_on) rcall pstr rcall newline sbi portc,3 ret strobe_off: rcall comm_ok ldi ZL, low(msg_strobe_off) ldi ZH, high(msg_strobe_off) rcall pstr rcall newline cbi portc,3 ret siren_on: rcall comm_ok ldi ZL, low(msg_siren_on) ldi ZH, high(msg_siren_on) rcall pstr rcall newline sbi portc,1 ret siren_off: rcall comm_ok ldi ZL, low(msg_siren_off) ldi ZH, high(msg_siren_off) rcall pstr rcall newline cbi portc,1 ret ignitor_on: rcall comm_ok ldi ZL, low(msg_ignitor_on) ldi ZH, high(msg_ignitor_on) rcall pstr rcall newline sbi portc,0 ret ignitor_off: rcall comm_ok ldi ZL, low(msg_ignitor_off) ldi ZH, high(msg_ignitor_off) rcall pstr rcall newline cbi portc,0 ret roll_on: rcall comm_ok ldi ZL, low(msg_roll_on) ldi ZH, high(msg_roll_on) rcall pstr rcall newline sbi portc,2 ret roll_off: rcall comm_ok ldi ZL, low(msg_roll_off) ldi ZH, high(msg_roll_off) rcall pstr rcall newline cbi portc,2 ret aux1_on: rcall comm_ok ldi ZL, low(msg_aux1_on) ldi ZH, high(msg_aux1_on) rcall pstr rcall newline sbi portc,4 ret aux1_off: rcall comm_ok ldi ZL, low(msg_aux1_off) ldi ZH, high(msg_aux1_off) rcall pstr rcall newline cbi portc,4 ret aux2_on: rcall comm_ok ldi ZL, low(msg_aux2_on) ldi ZH, high(msg_aux2_on) rcall pstr rcall newline sbi portc,5 ret aux2_off: rcall comm_ok ldi ZL, low(msg_aux2_off) ldi ZH, high(msg_aux2_off) rcall pstr rcall newline cbi portc,5 ret aux3_on: rcall comm_ok ldi ZL, low(msg_aux3_on) ldi ZH, high(msg_aux3_on) rcall pstr rcall newline sbi portc,6 ret aux3_off: rcall comm_ok ldi ZL, low(msg_aux3_off) ldi ZH, high(msg_aux3_off) rcall pstr rcall newline cbi portc,6 ret aux4_on: rcall comm_ok ldi ZL, low(msg_aux4_on) ldi ZH, high(msg_aux4_on) rcall pstr rcall newline sbi portc,7 ret aux4_off: rcall comm_ok ldi ZL, low(msg_aux4_off) ldi ZH, high(msg_aux4_off) rcall pstr rcall newline cbi portc,7 ret t5_on: rcall comm_ok ldi ZL, low(msg_t5_on) ldi ZH, high(msg_t5_on) rcall pstr rcall newline ldi temp,0xff out porta,temp ;sbi porta,1 ret t5_off: rcall comm_ok ldi ZL, low(msg_t5_off) ldi ZH, high(msg_t5_off) rcall pstr rcall newline ldi temp,0x01 out porta,temp ;cbi porta,1 ret ;********* SPI MEMORY SETUP *********************** Spisetup: ldi temp,0x00 sts eecounter,temp ldi r27,0x00 ;loads X high sbi portb,7 cbi portb,6 sbi portb,5 sbi portb,4 sbi ddrb,7 sbi ddrb,6 sbi ddrb,5 sbi ddrb,4 ldi temp,0x54 out spcr,temp ;sets spi data register for 01010000 or 0x50 ; which is no interrupt,spi on,msb first,master ; sck low idle, cpha guess low,sck=Fclk/4 ;ldi uart,'A' ;rcall cout ;in uart,spcr ;rcall phex ;ldi uart,' ' ret ;********* SPI WRITE ************************* EE_WREN: cbi portc,0 ldi temp,0x06 ;Write Enable (WREN) out spdr,temp rcall spiwait sbi portc,0 ret EE_WRSR: cbi portc,0 ldi temp,0x01 ;Write status register(WRSR) out spdr,temp rcall spiwait ldi temp,0x80 ;write enabled no protected memory out spdr,temp rcall spiwait sbi portc,0 rcall ee_wr_cycle ret EE_wr_cycle: ;needed for write cycle on ee 5ms @ 5vdc ldi temp2,23 EE_wc: ldi temp,0xff EE_wc2: dec temp brne EE_wc2 dec temp2 brne EE_wc ret ldi r26,eecounter st X+,adc1_l st X+,adc1_h cpi r26,128 ;use 128 instead of 127 so eepage is now breq eepagewrite sts eecounter,r26 mov uart,r26 rcall cout ret EEpagewrite: ldi ZL, low(msg_eepage) ldi ZH, high(msg_eepage) rcall pstr rcall newline EE_RDSR: cbi portc,0 ; cs low ee1 Active ldi temp,0x05 out spdr,temp rcall spiwait out spdr,temp rcall spiwait in spi,spdr sbi portc,0 ; cs high ee1 inactve ret spiwait: ;loop checking for spi done sending ;ldi uart,'C' ;rcall cout ;sbis spsr,7 in spi,spsr sbrs spi,7 rjmp spiwait ;jumps if spi not done yet. ret ;********* Menus **************************** mainmenu: rcall newline ldi ZL, low(msg_sublight) ldi ZH, high(msg_sublight) rcall pstr rcall newline ldi ZL, low(msg_main) ldi ZH, high(msg_main) rcall pstr rcall newline rcall newline ldi ZL, low(msg_entermaster) ldi ZH, high(msg_entermaster) rcall pstr rcall newline ldi ZL, low(msg_systemstatus) ldi ZH, high(msg_systemstatus) rcall pstr rcall newline ldi ZL, low(msg_autotrigger) ldi ZH, high(msg_autotrigger) rcall pstr rcall newline ldi ZL, low(msg_xmitdata) ldi ZH, high(msg_xmitdata) rcall pstr rcall newline ldi ZL, low(msg_erasenv) ldi ZH, high(msg_erasenv) rcall pstr rcall newline rcall newline rcall getchar ret ;*********Bi-color LED*********************** off: sbi portd,6 sbi portd,7 ret green: ;ldi temp,0xf0 ;out ddrd,temp ;ldi temp,0xff ;out portd,temp sbi portd,6 cbi portd,7 ret red: ;ldi temp,0xf0 ;out ddrd,temp ;ldi temp,0xff ;out portd,temp cbi portd,6 sbi portd,7 ret ;********* SS_out *************************** ss_on: sbi portc,5 ret ss_off: cbi portc,5 ret ;**********Delay Loop************************* ;this delay is .071179742 sec. delay: ldi temp,0xff ;1 delay_loop: dec temp ;1 breq delay_done ;1 when branching 2 delay2: ldi temp2,0xff ;1 delay_loop2: dec temp2 ;1 breq delay_done2 ;1 when branching 2 rjmp delay_loop2 ;2 delay_done2: rjmp delay_loop ;2 delay_done: ret ;4 ;**********Delayx Loop************************* ;This should be aprox 1.5 seconds delayx: ldi temp,0x15 ;1 delayx_loop: dec temp ;1 breq delayx_done ;1 when branching 2 delayx2: ldi temp2,0xff ;1 delayx_loop2: dec temp2 ;1 breq delayx_done2 ;1 when branching 2 delayx3: ldi uart,0xff delayx_loop3: dec uart breq delayx_done3 rjmp delayx_loop3 ;2 delayx_done3: rjmp delayx_loop2 delayx_done2: rjmp delayx_loop ;2 delayx_done: ret ;4 ;********A/D Read***************************** read_a2d: ldi adc1_l,0 ldi adc1_h,0 ldi adc2_l,0 ldi adc2_h,0 ldi adc3_l,0 ldi adc3_h,0 ldi adc4_l,0 ldi adc4_h,0 sbi porta,0 ;conv1 ;sbi porta,2 ;conv2 ;sbi porta,4 ;conv3 ;sbi porta,6 ;conv4 sbi portb,0 ;1 cbi portb,0 sbi portb,0 ;2 cbi portb,0 sbi portb,0 ;3 cbi portb,0 rcall getdatah ; x000 0000 0000 sbi portb,0 ;4 cbi portb,0 rcall getdatah ; 0x00 0000 0000 sbi portb,0 ;5 cbi portb,0 rcall getdatah ; 00x0 0000 0000 sbi portb,0 ;6 cbi portb,0 rcall getdatah ; 000x 0000 0000 sbi portb,0 ;7 cbi portb,0 rcall getdatal ; 0000 x000 0000 sbi portb,0 ;8 cbi portb,0 rcall getdatal ; 0000 0x00 0000 sbi portb,0 ;9 cbi portb,0 rcall getdatal ; 0000 00x0 0000 sbi portb,0 ;10 cbi portb,0 rcall getdatal ; 0000 000x 0000 sbi portb,0 ;11 cbi portb,0 rcall getdatal ; 0000 0000 x000 sbi portb,0 ;12 cbi portb,0 rcall getdatal ; 0000 0000 0x00 sbi portb,0 ;13 cbi portb,0 rcall getdatal ; 0000 0000 00x0 sbi portb,0 ;14 cbi portb,0 rcall getdatal ; 0000 0000 000x cbi porta,0 ;cbi porta,2 ;cbi porta,4 ;cbi porta,6 sbi portb,0 ;15 cbi portb,0 ret getdatah: lsl adc1_h lsl adc2_h lsl adc3_h lsl adc4_h sbic pina,1 inc adc1_h sbic pina,3 inc adc2_h sbic pina,5 inc adc3_h sbic pina,7 inc adc4_h ret getdatal: lsl adc1_l lsl adc2_l lsl adc3_l lsl adc4_l sbic pina,1 inc adc1_l sbic pina,3 sbr adc2_l,0 sbic pina,5 sbr adc3_l,0 sbic pina,7 sbr adc4_l,0 ret ;*********Config_A/D*************************** config_ad: ;sets portA for output only ldi temp, 0x55 ; set for 1 for output and 0 for input out ddra, temp ; data direction registor for port B ; See page 4-61 in data book ldi temp,0xaa out porta,temp ;sets portB,0 for output leaving 1-7 unchanged sbi ddrb,0 ;faster then lines below ;in temp,ddrb ;sbr temp,0 ; set for 1 for output and 0 for input ;ldi temp,0xff ;out ddrb, temp ; data direction registor for port B ; See page 4-61 in data book ret ;********* Config Relays *********************** config_relays: cbi porta,1 ;pa0 low for input high-z cbi porta,2 ;pa1 cbi portc,0 ;pc0 cbi portc,1 ;pc1 cbi portc,2 ;pc2 cbi portc,3 ;pc3 cbi portc,4 ;pc4 cbi portc,5 ;pc5 cbi portc,6 ;pc6 cbi portc,7 ;pc7 ret ;**************UART SECTION****************************************** ;********************************************* ; s_pstr: ; Sync-Serial output on the programming wires. ; s_pstr sends the ASCII string pointed to by ZL ; and ZH. Strings need to end in Zero. ; Registers Destroyed: uart, ZL, ZH ; Usage: ; msg_start: ; .db "Start ", 0 ; ldi ZL, low(msg_start) ; ldi ZH, high(msg_start) ; rcall s_pstr ;********************************************* pstr: push r0 clc rol zl ;Program Data is really at Z * 2 rol zh pstr_loop: lpm ;Loads the byte pointed to by Z into R0 mov uart, r0 cpi uart, 0x00 breq pstr_done rcall cout ;Change this to cout for RS232 subi zl, low(-1) ;inc Z sbci zh, high(-1) rjmp pstr_loop pstr_done: pop r0 ret cout: push uart cout1: in uart, USR ;read status reguster sbrs uart, 5 ;is data register ready? rjmp cout1 ;no, try again pop uart out UDR, uart ;xmit contents of uart ret newline: ldi uart,13 rcall cout ldi uart,10 rcall cout ret phex: phex8: push temp push uart swap uart andi uart,15 ldi temp,246 add uart,temp brcc phex_b ldi temp,7 add uart,temp phex_b: ldi temp,58 add uart,temp rcall cout pop uart phex1: push uart andi uart,15 ldi temp,246 add uart,temp brcc phex_c ldi temp,7 add uart,temp phex_c: ldi temp,58 add uart,temp rcall cout pop uart pop temp ret cint: push temp ldi uart,0xff cint1: dec uart breq no_cint ;waits for x number of trys in temp,USR sbrs temp,7 rjmp cint1 in uart,UDR pop temp ret no_cint: ;If cin had no ready flag with in time alotted it returns 0xff ldi uart,0xff pop temp ret cin: in uart,USR sbrs uart,7 rjmp cin in uart,UDR ret Getchar: ldi uart,'/' rcall cout rcall cint cpi uart,0xff brne getchar_ rcall delay ldi uart,0x0d rcall cout ldi uart,'-' rcall cout rcall cint cpi uart,0xff brne getchar_ rcall delay ldi uart,0x0d rcall cout ldi uart,'\' rcall cout rcall cint cpi uart,0xff brne getchar_ rcall delay ldi uart,0x0d rcall cout ldi uart,'|' rcall cout rcall cint cpi uart,0xff brne getchar_ rcall delay ldi uart,0x0d rcall cout rjmp getchar getchar_: ret ;********* Messages ************************* msg_start: .db "Start ", 0 msg_Test: .db "This is a TEST!!!! ", 0 msg_OK: .db "OK ", 0 msg_Error: .db "Error", 0 msg_Prompt: .db "LTC>", 0 msg_sublight: .db "SubLight Aerospace Data/logging transmitter",0 msg_AESS_start: .db "AESS/PSAS Launch Tower Controler",0 msg_main: .db "Main Menu",0 msg_erasenv: .db "5) Erase NV Ram",0 msg_xmitdata: .db "4) Transmit logged data",0 msg_autotrigger: .db "3) Auto trigger menu",0 msg_triggerlevel: .db "1) Set auto trigger voltage level",0 msg_beginauto: .db "2) Start auto trigger",0 msg_gotomain: .db "(M)ain Menu",0 msg_yn: .db "Are you sure? Yes or No?",0 msg_entermaster: .db "1) Enter Maser Arming code",0 msg_firecontrol: .db "Fire control menu",0 msg_10sec: .db "1) T-10 second countdown",0 msg_5sec: .db "5) T-5 second countdown",0 msg_abort: .db "Press a key to ABORT stop countdown.",0 msg_systemstatus: .db "2) System Status",0 msg_accessdenied: .db "ACCESS DENIED Enter Master Arming Code!",0 msg_eepage: .db "EEpage write initiated!",0 msg_strobe_on: .db "Strobe ON ",0 msg_Ignitor_on: .db "Ignitor ON ",0 msg_siren_on: .db "Siren ON ",0 msg_roll_on: .db "Rollerons ON ",0 msg_t5_on: .db "T-5 Signal ON-LINE ",0 msg_aux1_on: .db "AUX No. 1 ON ",0 msg_aux2_on: .db "AUX No. 2 ON ",0 msg_aux3_on: .db "AUX No. 3 ON ",0 msg_aux4_on: .db "AUX No. 4 ON ",0 msg_strobe_off: .db "Strobe OFF ",0 msg_Ignitor_off: .db "Ignitor OFF ",0 msg_siren_off: .db "Siren OFF ",0 msg_roll_off: .db "Rollerons OFF ",0 msg_t5_off: .db "T-5 Signal OFF-LINE ",0 msg_aux1_off: .db "AUX No. 1 OFF ",0 msg_aux2_off: .db "AUX No. 2 OFF ",0 msg_aux3_off: .db "AUX No. 3 OFF ",0 msg_aux4_off: .db "AUX No. 4 OFF ",0 msg_status: .db "STATUS",0