Humm B

I Finaly Started The Humm B.

This is an ongoing project that will change over time

i will post pictures soon (I hope)

i still need to figure out a good motor reversing circuit that will work with a pic.

I plan to use pics to controle the basic operations and sencors in a sort of nural network. perhaps adding a big brain at some point.

some wimpy code for a 16f84a pic, I just learned how to program these. It is just a bump sensor thing for the moment.:

 

;**********************************************************************
; *
; This file is a basic code template for assembly code generation *
; on the PIC16F84A. 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 (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: humm.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: P16F84A.INC *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************


list p=16F84A ; list directive to define processor
#include <p16F84a.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

; '__CONFIG' directive is used to embed configuration data 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
w_temp EQU 0x0C ; variable used for context saving
status_temp EQU 0x0D ; variable used for context saving
COUNT1 equ 08h ;First counter for our delay loops
COUNT2 equ 09h ;Second counter for our delay loops
COUNT3 EQU 0Ch ;Third delay loop
TURN1 EQU 0Dh ;Turn control for forward bump
;**********************************************************************
RESET_VECTOR CODE 0x0000 ; processor reset vector
goto start ; go to beginning of program

ISR CODE 0x0004 ; interrupt vector location

Interrupt:

movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register

; Place ISR Here

movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt

MAIN_PROGRAM CODE

start:

;****Set up the port****

bsf STATUS,5 ;Switch to Bank 1
movlw b'00111' ; 0 w for TRISA
movwf TRISA ;set TRISA to output.
movlw b'00000000' ;set w for TRISB
movwf TRISB ;set TRISB
bcf STATUS,5 ;Switch back to Bank 0
CLRF PORTA
CLRF PORTB
Program_Start

call Test

goto Program_Start ;loop back
;Subroutines
Test ;Test Sensors
BTFSS PORTA,0 ;Test Forward
call ForwardSensor
BTFSS PORTA,1 ;Test Left
call LeftSensor
BTFSS PORTA,2 ;Test Right
call RightSensor
call Forward
Return

ForwardSensor
BTFSC TURN1,1
call RLeft
BTFSS TURN1,1
call RRight
call Forward
Return

LeftSensor
BSF TURN1,1
call FRight
call Forward
Return

RightSensor
BCF TURN1,1
call FLeft
call Forward
Return

Forward ;Go Forward
CLRF PORTB ;Clear Port B
BSF PORTB,0 ;Set Forward Bit
Return

Reverse ;Go Backward
CLRF PORTB ;Clear Port B
BSF PORTB,1 ;Set Reverse Bit
Return

FLeft ;Turn left
CLRF PORTB ;Clear Port B
BSF PORTB,2 ;Set Left Bit
BSF PORTB,0 ;Set Forward Bit
call Delay ;Wait 0.25 sec
Return

FRight ;Turn Right
CLRF PORTB ;Clear Port B
BSF PORTB,3 ;Set Right Bit
BSF PORTB,0 ;Set Forward Bit
call Delay ;Wait 0.25 sec
Return

RLeft ;Turn left
CLRF PORTB ;Clear Port B
BSF PORTB,2 ;Set Left Bit
BSF PORTB,1 ;Set Reverse Bit
call Delay ;Wait 0.25 sec
call FRight ;Forward turn
Return

RRight ;Turn Right
CLRF PORTB ;Clear Port B
BSF PORTB,3 ;Set Right Bit
BSF PORTB,1 ;Set Reverse Bit
call Delay ;Wait 0.25 sec
call FLeft ;Forward turn
Return

Delay
; count down 250x250x4= ~0.25 seconds
; setup numbers for count down
movlw b'11111010' ;250 w
movwf COUNT2 ;250 eeadr
movlw b'11111010' ;250 w
movwf COUNT1 ;250 EEDATA
movlw b'00000100' ;4 w
movwf COUNT3 ;4 0Ch
Loop1 ;Count down from 250,000
decfsz COUNT1,1 ;count down from 250x250x4
goto Loop1 ; go to loop1
movlw b'11111010' ;250 w
movwf COUNT1 ;250 EEDATA
decfsz COUNT2,1 ;count down from 250x4
goto Loop1 ; go to loop1
movlw b'11111010' ;250 w
movwf COUNT2 ;250 eeadr
decfsz COUNT3,1 ; count down from 4
goto Loop1
return

goto $

END ; directive 'end of program'