📄 map_bot.asm
字号:
MOVF pwm_cycle,W
SUBWF pwm_value+1,W
BTFSS 0x03,Carry
BCF 0x06,pwm_out_1
; if (pwm_cycle > pwm_value[2]) pwm_out_2 = 0;
BCF 0x03,RP0
BCF 0x03,RP1
MOVF pwm_cycle,W
SUBWF pwm_value+2,W
BTFSS 0x03,Carry
BCF 0x06,pwm_out_2
; if (pwm_cycle > pwm_value[3]) pwm_out_3 = 0;
BCF 0x03,RP0
BCF 0x03,RP1
MOVF pwm_cycle,W
SUBWF pwm_value+3,W
BTFSS 0x03,Carry
BCF 0x06,pwm_out_3
;
; // TMR2 = 0xe0; // reset timer this is about 500 hz
;
; TMR2 = 0xd0; // reset timer this is about 500 hz
MOVLW .208
BCF 0x03,RP0
BCF 0x03,RP1
MOVWF TMR2
;
; // TMR2 = 0x20;
;
; // See if we are waiting to start the A->D
; // Also, make sure it's not already running
; if (wait_analog && !GO)
MOVF wait_analog,1
BTFSC 0x03,Zero_
GOTO m043
BTFSC 0x1F,GO
GOTO m043
; {
; // Reduce wait count
; wait_analog--;
DECF wait_analog,1
;
; // Done waiting, start the converter
; if (wait_analog == 0)
BTFSC 0x03,Zero_
; GO = 1;
BSF 0x1F,GO
; }
;
; TMR2IF = 0; // clear flag
m043 BCF 0x03,RP0
BCF 0x03,RP1
BCF 0x0C,TMR2IF
; }
;
; // The analog to digital converter is done
; if (ADIF)
m044 BCF 0x03,RP0
BCF 0x03,RP1
BTFSS 0x0C,ADIF
GOTO m045
; {
; // Save current values
; analog_low[cur_analog] = ADRESL;
MOVLW .77
ADDWF cur_analog,W
MOVWF FSR
BCF 0x03,IRP
BSF 0x03,RP0
MOVF ADRESL,W
MOVWF INDF
; analog_high[cur_analog] = ADRESH & 0x03;
MOVLW .85
BCF 0x03,RP0
ADDWF cur_analog,W
MOVWF FSR
BCF 0x03,IRP
MOVLW .3
ANDWF ADRESH,W
MOVWF INDF
;
; // Setup for next analog channel
; cur_analog++;
INCF cur_analog,1
;
; // Wrap arund back to first
; if (cur_analog >= NUM_ANALOG) cur_analog = 0;
MOVLW .8
SUBWF cur_analog,W
BTFSC 0x03,Carry
CLRF cur_analog
;
; // Create mask for new channel
; unsigned char mask = cur_analog << 3;
BCF 0x03,Carry
BCF 0x03,RP0
BCF 0x03,RP1
RLF cur_analog,W
MOVWF mask
BCF 0x03,Carry
RLF mask,1
BCF 0x03,Carry
RLF mask,1
;
; ADCON0 &= 0b.1100.0111;
MOVLW .199
ANDWF ADCON0,1
; ADCON0 |= mask; // mask off channel bits, and set new channel
MOVF mask,W
IORWF ADCON0,1
;
; // Setup to wait to fire the go signal
; wait_analog = 200;
MOVLW .200
MOVWF wait_analog
;
; ADIF = 0; // Clear flag
BCF 0x0C,ADIF
; }
;
; int_restore_registers
m045 BCF 0x03,RP0
BCF 0x03,RP1
SWAPF svrSTATUS,W
MOVWF STATUS
SWAPF svrWREG,1
SWAPF svrWREG,W
;}
RETFIE
;/* end of interrupt service routine */
;
;/**************************
;** End of interrupt Code **
;**************************/
;
;
;/***********************
;** Serial functions **
;***********************/
;
;/* Set the serial port to 9600 8N1 */
;void setup_serial(void)
;{
setup_serial
;// SPBRG = 129; // divisor for 9600 baud
; SPBRG = 64; // divisor for 19200 baud
MOVLW .64
BSF 0x03,RP0
BCF 0x03,RP1
MOVWF SPBRG
;
; TXSTA = 0b.0010.0100; // transmitt enable, high speed
MOVLW .36
MOVWF TXSTA
; RCSTA = 0b.1001.0000; // serial enable
MOVLW .144
BCF 0x03,RP0
MOVWF RCSTA
;
; char ch = RCREG; // flush buffer
MOVF RCREG,W
MOVWF ch
; ch = RCREG;
MOVF RCREG,W
MOVWF ch
; ch = RCREG;
MOVF RCREG,W
MOVWF ch
;}
RETURN
;/* end of setup serial */
;
;
;
;
;/*******************
;** Initialization **
;*******************/
;
;/* system startup */
;void startup( void )
;{
startup
; PORTA = 0; // clear ports
BCF 0x03,RP0
BCF 0x03,RP1
CLRF PORTA
; PORTB = 0;
CLRF PORTB
; PORTC = 0;
CLRF PORTC
; PORTD = 0;
CLRF PORTD
; PORTE = 0;
CLRF PORTE
;
; TRISA = 0b.1111.1111; // all inputs
MOVLW .255
BSF 0x03,RP0
MOVWF TRISA
; TRISB = 0b.0000.0001; // bit 0 is digital in 2, bit 3 is led1
MOVLW .1
MOVWF TRISB
; TRISC = 0b.1000.0000; // bit 7 is rx
MOVLW .128
MOVWF TRISC
;// TRISD = 0b.1100.0000; // D6, D7 radio in, all others digital out
;
; TRISD = 0b.0000.1111; // D6, D7 radio in, all others digital out
MOVLW .15
MOVWF TRISD
;
; TRISE = 0b.0000.0111; // E0-E2 digital in
MOVLW .7
MOVWF TRISE
;
;
;// ADCON0 = 0b.1000.0001 | mask;
;
; // clear core values before interrupts are turned on
;
; running_counter = 0;
BCF 0x03,RP0
CLRF running_counter
; recv_counter = 0;
CLRF recv_counter
;
;
; servo_mode = 0; // finite state machine for servo control
CLRF servo_mode
; cur_servo = 0; // current servo number
CLRF cur_servo
; pwm_cycle = 0; // state of pwm system
CLRF pwm_cycle
;
; pwm_value[0] = 0;
CLRF pwm_value
; pwm_value[1] = 0;
CLRF pwm_value+1
; pwm_value[2] = 0;
CLRF pwm_value+2
; pwm_value[3] = 0;
CLRF pwm_value+3
;
;
;
; // setup timer 0
; OPTION = 4; // prescaler divide by 16
MOVLW .4
BSF 0x03,RP0
MOVWF OPTION_REG
; T0CS = 0; // internel clock
BCF 0x81,T0CS
; TMR0 = 0; // clear the timer
BCF 0x03,RP0
CLRF TMR0
; T0IE = 1; // enable interrupt for timer 0
BSF 0x0B,T0IE
;
;
; // setup timer 1
; TMR1L = 0; // reset timer
CLRF TMR1L
; TMR1H = 0;
CLRF TMR1H
;
; TMR1ON = 0; // shut off timer to modify values
BCF 0x10,TMR1ON
;
; T1CKPS1 = 1; // setup prescaler
BSF 0x10,T1CKPS1
; T1CKPS0 = 0;
BCF 0x10,T1CKPS0
; T1OSCEN = 0; // shut off oscillator
BCF 0x10,T1OSCEN
;
; TMR1CS = 0; // internal clock
BCF 0x10,TMR1CS
; TMR1IE = 1; // enable interrupt
BSF 0x03,RP0
BSF 0x8C,TMR1IE
;
; TMR1ON = 1; // turn timer on
BCF 0x03,RP0
BSF 0x10,TMR1ON
; TMR1IF = 0; // clear interrupt flag
BCF 0x0C,TMR1IF
;
; TMR2 = 0xe0;
MOVLW .224
MOVWF TMR2
; TMR2ON = 1; // enable timer 2
BSF 0x12,TMR2ON
; TMR2IE = 1;
BSF 0x03,RP0
BSF 0x8C,TMR2IE
;
; servo_pos[0] = 0x80; // setup inital servo positions
MOVLW .128
BCF 0x03,RP0
MOVWF servo_pos
; servo_pos[1] = 0x80;
MOVLW .128
MOVWF servo_pos+1
; servo_pos[2] = 0x80;
MOVLW .128
MOVWF servo_pos+2
; servo_pos[3] = 0x80;
MOVLW .128
MOVWF servo_pos+3
; servo_pos[4] = 0x80;
MOVLW .128
MOVWF servo_pos+4
; servo_pos[5] = 0x80;
MOVLW .128
MOVWF servo_pos+5
;
; update_timeout = 0;
CLRF update_timeout
;
; reading_data = 0;
BCF 0x64,reading_data
; read_timeout = 0;
CLRF read_timeout
; cur_recv_byte = 0; // Waiting for first byte
CLRF cur_recv_byte
; cur_send_byte = 0; // Waiting for first byte
CLRF cur_send_byte
; last_valid = 1;
BSF 0x64,last_valid
;
; RCIF = 0; // Clear receive interrupt
BCF 0x0C,RCIF
; RCIE = 1; // Enable receive interrupts
BSF 0x03,RP0
BSF 0x8C,RCIE
;
; TXIF = 0; // Clear receive interrupt
BCF 0x03,RP0
BCF 0x0C,TXIF
; TXIE = 1; // Enable receive interrupts
BSF 0x03,RP0
BSF 0x8C,TXIE
;
;
; // Analog to Digital Setup
; cur_analog = 0;
BCF 0x03,RP0
CLRF cur_analog
;
;// ADCON1 = 0b.1000.0010; // RE0, 1, 2 : digital RA0,1,2,3,5 : analog
;
; ADCON1 = 0b.1000.0000; // RE0, 1, 2 : digital RA0,1,2,3,5 : analog
MOVLW .128
BSF 0x03,RP0
MOVWF ADCON1
;
;
; ADCS1 = 1; // Fosc/32 clocl
BCF 0x03,RP0
BSF 0x1F,ADCS1
; ADCS0 = 0;
BCF 0x1F,ADCS0
; ADCON0 &= 0b.1100.0111;
MOVLW .199
ANDWF ADCON0,1
; ADON = 1; // turn on converter
BSF 0x1F,ADON
;
; ADIF =0;
BCF 0x0C,ADIF
; ADIE =1;
BSF 0x03,RP0
BSF 0x8C,ADIE
;
; GO = 1;
BCF 0x03,RP0
BSF 0x1F,GO
;
; GIE = 1; // interrupts allowed
BSF 0x0B,GIE
; PEIE = 1; // enable periphial interrupts
BSF 0x0B,PEIE
;
;encoder_0_count = 0;
CLRF encoder_0_count
;encoder_0_speed = 0;
CLRF encoder_0_speed
;
;
; encoder_low[0] = 0;
CLRF encoder_low
; encoder_high[0] = 0;
CLRF encoder_high
; encoder_low[1] = 0;
CLRF encoder_low+1
; encoder_high[1] = 0;
CLRF encoder_high+1
; encoder_low[2] = 0;
CLRF encoder_low+2
; encoder_high[2] = 0;
CLRF encoder_high+2
; encoder_low[3] = 0;
CLRF encoder_low+3
; encoder_high[3] = 0;
CLRF encoder_high+3
;
;last_dir = 0;
CLRF last_dir
;run_count = 0;
CLRF run_count
;}
RETURN
;/* end of startup */
;
;/**************************
;** End of Initialization **
;**************************/
;
;
;
;/****************************************
;** Serial command interface functions **
;****************************************/
;
;
;
;/* deal with digital out command */
;/*void digital_out_command ( void )
;{
; unsigned char n = get_hex_nibble(); // get output number
;
; if (n > 5) return; // range check
;
; unsigned shift = 1 << n; // create bit mask
;
; unsigned char v = get_hex_nibble(); // get value (on or off)
;
; if( v == 0)
; {
; shift = 255 - shift; // and mask
; PORTD &= shift;
; }
;
; if (v == 1)
; PORTD |= shift; // or mask
;}*/
;/* end of digital_out_command */
;
;/* return the valur of a digital input */
;/*bit get_digital_value(unsigned char n)
;{
; if (n == 0) return(digital_in_0); else
; if (n == 1) return(digital_in_1); else
; if (n == 2) return(digital_in_2); else
; if (n == 3) return(digital_in_3); else
; if (n == 4) return(digital_in_4);
;
; return(0);
;}*/
;/* end of get_digital_value */
;
;
;/***********************************************
;** End of serial command interface functions **
;***********************************************/
;
;/* Read data from sonar sensor */
;// The parmeter is the input /output pair number
;// for example passing '2' will use input 2 and output 2
;//
;/*void get_sonar_command( void )
;{
; unsigned char n = get_hex_nibble();
;
; unsigned char mask = 1 << n;
;
; PORTD |= mask; // turn output on
;
; delay(0x8);
;
; PORTD &= ~mask; // turn output off
;
; TMR1H = 0;
;
; while(!get_digital_value(n) && TMR1H < 0x80);
;
; TMR1H = 0;
; TMR1L = 0;
;
; // Read the pulse width
; while(get_digital_value(n) && TMR1H < 0x80);
;
; unsigned char l = TMR1L; // Save low order, it will change during transmittion
;
; send_hex(TMR1H);
; send_hex(l);
;}*/
;/* End of read sonar */
;
;
;
;
;
;/* main function */
;void main ( void )
;{
main
; startup();
CALL startup
;
; setup_serial();
CALL setup_serial
;
; while (1); // infinte loop
m046 GOTO m046
ORG 0x0000
DATA 018AH
DATA 0000H
DATA 0000H
ORG 0x2007
DATA 3FF2H
END
; *** KEY INFO ***
; 0x0004 P0 559 word(s) 27 % : ISR
; 0x0233 P0 16 word(s) 0 % : setup_serial
; 0x0243 P0 109 word(s) 5 % : startup
; 0x02B0 P0 3 word(s) 0 % : main
; RAM usage: 89 bytes (5 local), 247 bytes free
; Maximum call level: 1 (+1 for interrupt)
; Codepage 0 has 691 word(s) : 33 %
; Codepage 1 has 0 word(s) : 0 %
; Codepage 2 has 0 word(s) : 0 %
; Codepage 3 has 0 word(s) : 0 %
; Total of 691 code words (8 %)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -