;********************************************************************** ; This file is a basic code template for object module code * ; generation on the PIC16F57. This file contains the * ; basic code building blocks to build upon. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler and linker. * ; * ; Refer to the respective PIC data sheet for additional * ; information on the instruction set. * ; * ; * ;********************************************************************** ; * ; Filename: control_board_v1.asm * ; Date: 6 August 2012 * ; File Version: 1 * ; * ; Author: Bob Harris * ; Company: * ; * ; * ;********************************************************************** ; * ; Files required: P16F57.INC * ; * ; * ; * ;********************************************************************** ; * ; Notes: * ; MOSFET amplifier controller board * ; * ; * ; * ;********************************************************************** list p=16F57 ; list directive to define processor #include ; processor specific variable definitions ; RGH 4-2 of datasheet indicates use HS osc __CONFIG _CP_OFF & _WDT_OFF & _HS_OSC ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ; ;***** VARIABLE DEFINITIONS ; RGH allocates space for Unintialise DATA, UDATA ; RGH the label TEMP_VAR is only needed if there is more than one UDATA section ; RGH the variable being stored is called temp TEMP_VAR UDATA INPUT_STATUS RES 1 ; variable definition, 1 byte wide OUTPUT_STATUS RES 1 BAND_INPUT_STATUS RES 1 BAND_OUTPUT_STATUS RES 1 COUNT1 RES 1 COUNT2 RES 1 ATT_BUT_ALRDY_IN RES 1 ATTEN_OUTPUT_STATUS RES 1 ON_BUT_ALRDY_IN RES 1 ON_OUTPUT_STATUS RES 1 ;********************************************************************** RESET_VECTOR CODE 0x7FF ; processor reset vector goto main MAIN CODE 0x0000 ; RGH place the next bit of code at 0x0000 with the label start ; RGH suspect label only needed if there is more than one code section main ; setup all the I/O pins ; PORTA only has lower 4 bits available, set all to input movlw b'11111111' ; A 0 in tris sets corresponding bit to input, 1 sets it to output tris PORTA movlw b'11111111' ; PORTB has 8 bits available, set all to input tris PORTB movlw b'00000000' ; PORTC has 8 bits available, set all to output tris PORTC ; now the main code to initial read in pushbuttons and operate relays movfw PORTB ; read in push buttons iorlw 0x00 ; check if any pressed in by setting the zero flag if none are pressed btfss STATUS,Z ; test zero flag and jump next instruction (the goto) if not set, ie button pressed goto start_up_sequence ;if button pressed at power on then do something different or drop out to cool_start cool_start movlw b'01000000' movwf PORTC movlw .255 call delay movlw b'00000001' movwf PORTC movlw .255 call delay movlw b'00000010' movwf PORTC movlw .255 call delay movlw b'00000100' movwf PORTC movlw .255 call delay movlw b'00001000' movwf PORTC movlw .255 call delay movlw b'00010000' movwf PORTC movlw .255 call delay movlw b'00100000' movwf PORTC movlw .255 call delay movlw b'01111111' movwf PORTC movlw .255 call delay final_init movlw b'00100000' ; set default band to 28MHz; Atten to off; On to off movwf PORTC movwf BAND_OUTPUT_STATUS ; save band output status movlw b'00000000' ; initialise things to off movwf ATT_BUT_ALRDY_IN movwf ATTEN_OUTPUT_STATUS movwf ON_BUT_ALRDY_IN movwf ON_OUTPUT_STATUS main_loop movfw PORTB ; read in all push buttons iorlw 0x00 ; check if any pressed in by setting the zero flag if none are pressed btfsc STATUS,Z ; test zero flag and jump next instruction (the goto) if not set, ie button not pressed; goto butt_in movlw 0x00 movwf ATT_BUT_ALRDY_IN ; clear button already in flagS movwf ON_BUT_ALRDY_IN goto main_loop butt_in movlw .10 ; now wait for debounce time call delay movfw PORTB ; read in all push buttons again iorlw 0x00 ; check if any pressed in by setting the zero flag if none are pressed btfss STATUS,Z ; test zero flag and jump next instruction (the goto) if not set, ie button pressed; goto chk_att_on ; a button pressed so check if atten or on goto main_loop ; not set so carry on scanning inputs chk_att_on movfw PORTB ; save button status movwf INPUT_STATUS andlw b'00111111' ; now mask off "Atten" and "On" buttons movwf BAND_INPUT_STATUS iorlw 0x00 ; check by setting the zero flag if none of band buttons are pressed btfsc STATUS,Z ; test zero flag and jump next instruction (the goto) if not set, ie button pressed; goto atten_or_on_check ; no band button pressed, check if Atten or On ; now set up the band output movfw BAND_OUTPUT_STATUS subwf BAND_INPUT_STATUS ; check if button pressed is same as last button press, using subwf as a compare btfsc STATUS,Z ; if same, zero flag set, so loop round goto main_loop ; same button pressed as before so loop round movfw PORTB ; BAND_INPUT_STATUS destroyed on subwf so need to restore andlw b'00111111' ; now mask off "Atten" and "On" buttons movwf BAND_INPUT_STATUS ; save band input status movwf BAND_OUTPUT_STATUS ; save required band output status call combine ; combine output bits goto main_loop ; loop round atten_or_on_check movfw INPUT_STATUS ; get button status andlw b'01000000' ; mask off all except atten iorlw 0x00 ; check by setting the zero flag if atten is not pressed btfsc STATUS,Z ; test zero flag and jump next instruction (the goto) if not set, ie atten pressed; goto on_pressed ; must be On since all others have now been checked movfw ATT_BUT_ALRDY_IN ; check already handled atten button press iorlw 0x00 btfss STATUS,Z ; if not handled, result is zero so handled, else loop round goto main_loop movfw ATTEN_OUTPUT_STATUS ; get current atten_output_status xorlw b'01000000' ; XOR to invert the output bit movwf ATTEN_OUTPUT_STATUS ; save back in register movlw b'00000001' movwf ATT_BUT_ALRDY_IN ; set the atten_button_already_in flag call combine goto main_loop on_pressed movfw ON_BUT_ALRDY_IN ; check already handled on button press iorlw 0x00 btfss STATUS,Z ; if not handled, result is zero so handled, else loop round goto main_loop movfw ON_OUTPUT_STATUS ; get current on_output_status xorlw b'10000000' ; XOR to invert the output bit movwf ON_OUTPUT_STATUS ; save back in register movlw b'00000001' movwf ON_BUT_ALRDY_IN ; set the atten_button_already_in flag call combine goto main_loop start_up_sequence ; at this stage no start_up sequence code goto final_init combine ; combines various output bits movfw BAND_OUTPUT_STATUS ; get required band output status iorwf ATTEN_OUTPUT_STATUS,0 ; combine with attenuator status iorwf ON_OUTPUT_STATUS,0 ; combine with on status movwf OUTPUT_STATUS ; save port output status movwf PORTC ; output to relays etc retlw 0 ; loop round delay ;taken from Gooligum tutorial, w contains delay movwf COUNT2 clrf COUNT1 dly1 nop decfsz COUNT1,f goto dly1 dly2 nop decfsz COUNT1,f goto dly2 decfsz COUNT2,f goto dly1 retlw 0 END ; directive 'end of program'