pic programing

Status
Not open for further replies.

iceberg25

New Member
hi ~all.
i am trying to program something to microchip pic16f877a by using mplab,who can help me check whether my script can run in pic or not?
help me to correct if got any error.
thanks.
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F877A.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************


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

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF


ORG 0x000
goto main

main STATUS equ 03h
TRISA equ 85h
TRISB equ 86h
PORTA equ 05h
PORTB equ 06h
movlw 02h
movwf STATUS
movlw 03h
movwf TRISA
movlw fch
movwf TRISB
clrf STATUS
start btfss PORTA,0
btfsc PORTA,1
goto stop
movlw 03h
movwf PORTB
goto start

stop movlw 00h
movwf PORTB
goto turn
turn movlw 01h
movfw PORTB
btfsc PORTA,0
btfss PORTA,1
goto start
goto turn
 
iceberg25 said:
stop movlw 00h
movwf PORTB
goto turn
turn movlw 01h
movfw PORTB

The last line from these few should read

movwf PORTB

There may be other faults.
 
vectorsd said:
who can design for me an 8-digit frequency counter using pic16f684 , im struggling.

I'll do it for a fee... Lets say $100 per hour based on an 8 hour day.... Shouldn't take more than a couple of weeks to get the code, schematic and PCB design sorted.... And I'll retain the copyright and licencing rights to the design... Still want someone to do the work for you???
 
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF


ORG 0x000
goto main

Main
STATUS equ 03h ; not needed, defined in INC statment
TRISA equ 85h ; not needed
TRISB equ 86h ; not needed
PORTA equ 05h ; not needed
PORTB equ 06h ; not needed
clrf PORTB ; clear the ports
clrf PORTA
movlw 02h
movwf STATUS ; goto Bank 1
movlw 03h
movwf TRISA ;set Port A to 00000011 (RA0 and RA1 are inputs)
movlw fch
movwf TRISB ;set Port B 11111100 (RB0 and RB1 are outputs)
clrf STATUS ; goto Bank 0

Start
btfss PORTA,0 ; check input pin RA0 and skip if 1
btfsc PORTA,1 ; check input pin RA1 and skip if 0
goto stop
movlw 03h
movwf PORTB ;set the outputs pins RB0 and RB1 to 1
goto start

Stop
movlw 00h
movwf PORTB ;clear Port B
goto turn ;not realy needed since it will drop thru anyways

Turn
movlw 01h
movwf PORTB ;set the outputs pin RB0 to 1
btfsc PORTA,0; check input pin RA0 and skip if 0
btfss PORTA,1; check input pin RA1 and skip if 1
goto start
goto turn

This would be easier to check if we knew what this program is intended to do. By the subroutine names, it looks like you want to start, stop and turn something. Maybe two motors on a robot?. However, the stop routine runs imediately into the turn routine, which I don't think is what u want. Also note that if RA0 and RA1 pins are switches, there is no debounce routine to wait for the switch state to settle before calling a subroutine.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…