Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help On Using Timer0 in 16f877

Status
Not open for further replies.

crowinu

Member level 2
Joined
Apr 1, 2005
Messages
48
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,621
using tmr0 with 16f877

hi guys,

i am doing a project for my schoolwork (PIC controlled dimmer) and i need to use the timer0, some guys explained something but i didnt get the concept on how to use it. I need some help in using timer0 if u guys iwsh to help me. another thing i am using assembly language not c :|, i guess it makes it more diffcult. i need to do something like this, every 1s a smal routine is called.
10x for any help

crowinu.
 

requirments are not based on programming since my course is focused on electronics, so it's the circuit most important, but to get the circuit to work i needthw write coding. i read the datasheet and it wast that helpfl for me, i need some code example. i need to use timer 0 to repeat a routine every 1second and they told me to use the timer0 not delays. i am a begginer in timers i know nothing. if u give me some help it will help alot :|.

10x 4 now
 

Code:
#define CRYSTAL 4194304


	PROCESSOR PIC16F877
	TITLE	"TMR0"
	INCLUDE "P16F877.INC"
	LIST	p=16F877, r=DEC
	__CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC & _BODEN_OFF & _LVP_OFF	
	ERRORLEVEL -302,-305,-306



RESET_V	EQU	0x0000

	CBLOCK	0x20
		tmr0count
	ENDC

	ORG	RESET_V
	clrf	STATUS
	clrf	INTCON	
	goto	Init

; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
main:	
WaitTmr0Overflow:
	btfss	INTCON,T0IF
	goto	WaitTmr0Overflow
	bcf	INTCON,T0IF
; here we have 0.0625 seconds delay
	decfsz	tmr0count,F
	goto	WaitTmr0Overflow
	movlw	16
	movwf	tmr0count
; here wa have 1 second delay
	call	UserSubroutineEvery1Second

	goto	main

UserSubroutineEvery1Second:
;
;	Some code
;
	return

; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Init:	clrf	PIR1
	clrf	PIR2		
        clrf    PORTA
       	clrf	PORTB
        clrf    PORTC
	clrf	T1CON
	clrf	T2CON
	clrf	SSPCON
	clrf	CCP1CON
	clrf	ADCON0
	bsf	_RP0		; bank1
	clrf	PIE1	
	clrf	PIE2	        
	movlw	0x06
	movwf	ADCON1		; Set PORTA digital
	movlw	B'11010000'
	movwf	TRISA
	movlw	B'11111011'
	movwf	TRISB
	movlw	B'11011000'
	movwf	TRISC
; TMR0 delay:
; 4 / 4194304 = 9.5367431E-07
; TMR0 prescaler 1:256
; Delay = 256 * 256 * 9.5367431E-07 = 0.0625 seconds
; if tmr0count is 16, then total Delay is: 16 * 0.0625 = 1 second
	movlw	0x07		; 1:256, pull-up enabled
	movwf	OPTION_REG	; 1:256 TMR0 prescaler
	bcf	_RP0		; bank0
	movlw	16
	movwf	tmr0count
	clrf	TMR0
	bcf	INTCON,T0IF
	bcf	INTCON,T0IE
	goto	main


	END
 

    crowinu

    Points: 2
    Helpful Answer Positive Rating
10x pirev, it was very help full :). 10x alot again. i will do something.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top