• 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.

binary counter 4 bits

Status
Not open for further replies.

salah_pic

New Member
Hello;
I'm wrinting a programm to realize a binary counter but when i simulate it on ISIS it work's like a decounter from 1110 to 0000 ( decompteur de 0x0E to 0x00).
LED0 connected to RB0 ( LSB )
LED1 connected to RB1
LED2 connected to RB2
LED3 connected to RB3 ( MSB ); the code is:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LIST p=16F877A ; Définition de processeur
#include "P16F877A.INC" ; fichier include

__CONFIG _CP_OFF & _DEBUG_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC




errorlevel -207
errorlevel -205
errorlevel -302
errorlevel -224 ;pour supprimer les warnings

;*********************************************************************
; DEFINE *
;*********************************************************************

AN1 EQU 0X6E
AN2 EQU 0X6D
AN3 EQU 0x6A
memo EQU 0x60

;**********************************************************************
; DEMARRAGE SUR RESET *
;**********************************************************************

org 0x00 ; Adresse de départ après reset
goto init ; Adresse 0: initialiser
org 0x10
;*********************************************************************
; INITIALISATIONS *
;*********************************************************************

init

bsf STATUS,RP0
bcf STATUS,RP1 ; selection banque1
movlw b'00000000'
movwf TRISB ; port b en sortie
bcf STATUS,RP0
bcf STATUS,RP1 ; banque0
goto start



;*********************************************************************
; PROGRAMME PRINCIPAL *
;*********************************************************************

start

movwf memo ; initialiser un registre tampon
movf memo,w ; memo dans portb
movwf PORTB
call tempo
t : incf memo
call tempo ; appeler la temporisation de 0.5s
movf memo,PORTB ; portb dans w
movf memo,w
sublw 0x0f ; 15-w dans w
movwf PORTB ; afficher sur portb
btfss STATUS,Z ; si oui goto start
goto t ; si non incrementer
goto start ; boucler


;*********************************************************************
; SOUS-ROUTINE DE TEMPORISATION *
;*********************************************************************
;---------------------------------------------------------------------
; Cette sous-routine introduit un retardement.
;---------------------------------------------------------------------

tempo
movlw 0xff
movwf AN1
movlw 0xff
movwf AN2
movlw 0x03
movwf AN3

temp decfsz AN1,f
goto temp
movlw 0xff
movwf AN1
decfsz AN2,f
goto temp
movlw 0xff
movwf AN2
decfsz AN3,f
goto temp

return ; retour de la sous-routine

END
 

be80be

Well-Known Member
Whats it's not doing
Code:
errorlevel -302
just use that 1 and build with mpasm in mplab see what it tells you.
A lot of times code will run on isis but not in a real chip. isis is more for giving than
mpasm in mplab.
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top