• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

need help...

Status
Not open for further replies.

anshi83

New Member
i tried writing some code

;expected result is a high on portC,0 when
;start bit is detected.
;**********************************************************

__config _LVP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF & _BODEN_OFF & _DEBUG_OFF


include "p16f877.inc"
STORAGE1 set 0x20
INNERWHEEL set 0x21
OUTERWHEEL set 0x22
COUNTER set 0x23

; Start at the reset vector
org 0x000
goto Start
org 0x004
Interrupt
retfie
Start
bsf STATUS,RP0 ;bank 1
bcf STATUS,RP1
movlw H'FF'
movwf TRISA ;porta [0] input
movlw H'00'
movwf TRISC ;portc [7-0] outputs
movlw H'00'
movwf TRISB ;portc [7-0] outputs
movlw H'07'
movwf OPTION_REG ;set prescaler
movlw H'06'
movwf ADCON1 ;set input bits to be digital

bcf STATUS,RP0 ;bank 0
clrf PORTC

Main

WaitS btfss PORTA,0 ;if high, then skip (break out
;of loop)
goto WaitS
clrf TMR0

WaitT btfsc PORTA,0 ;wait until a low pulse is
;obtained.
goto WaitT

movf TMR0,W ;TMR0 value is in W
sublw .35 ;W = .35 - W
btfss STATUS,CARRY ;if W> .35 then carry bit will
;be 0
bsf PORTC,0
goto Main
end

it should detect a .35 TMR0 cycle long high pulse (or longer) from portA, bit 0,... but it doesn't work.... i don't know why, but nothing appears in PORTC bit 0..... can anyone tell me why?
 

Eclipsed

New Member
I'm not too good at assembly, but it looks like you need a pulse LESS than 35 cycles to set PORTC bit 0. if W> .35 then carry bit will be 1 not 0.So change your btfss to btfsc.Also I am not familar with the "." in .35
 

Exo

Active Member
You need to set Timer0's clock source mux and prescaler before it starts running

Read the datasheet... prescaler and clock selection mux for TMR0 is done with OPTION_REG
 

Exo

Active Member
Eclipsed said:
I'm not too good at assembly, but it looks like you need a pulse LESS than 35 cycles to set PORTC bit 0. if W> .35 then carry bit will be 1 not 0.So change you btfss to btfsc.Also I am not familar with the "." in .35
.35 means 35 decimal
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top