#include<xc.h>
#include<Delays.h>
#define LED1 RB0
void main(){
PORTB = 0x00; /// all Pin of PORTB to 0
TRISB = 0x00; /// to make all PORTB PIN output
while(1){
LED1 = ~LED1; // Toggle the State of LED Every time
Delay_ms(50)
Delay_ms(50)
Delay_ms(50)
Delay_ms(50)
}
}
#include<xc.h>
#include<Delays.h>
#define LED1 RB0
#define Key RB1
void main(){
PORTB = 0x00; /// all Pin of PORTB to 0
TRISB0 = 0; /// OUTPUT
TRISB1 = 1; /// INPUT
while(1){
if (key == 1){
LED1 = ~LED1; // Toggle the State of LED Every time
}
}
}
bsf STATUS,5 ;Switch to Bank 1
movlw 00h ;Set the Port A pins to outputs
movwf TRISA
movlw 0ffh ;disable a-d
movwf ADCON1
bcf STATUS,5 ;Switch back to Bank 0
#include <p16f877a.inc>
__config 3f39
Start goto main
main call sys_init
loop call Blink_LED
goto loop
Blink_LED bsf PORTC,7
goto Blink_LED
sys_init clrf PORTC
bsf STATUS,5
bcf TRISC,7
bcf STATUS,5
clrf PORTC
return
end
PORTC and the TRISC Register
PORTC is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISC. Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input (i.e., put the corresponding output driver in a High-Impedance mode). Clearing a TRISC bit (= 0) will make the corresponding PORTC pin an output (i.e.,put the contents of the output latch on the selected pin).
TRISC = 0b00001111; /// will make Port C4:7 outputs and C0:3 inputs
List P=16F877A
include <P16F877A.inc>
__CONFIG _CP_OFF& _WRT_OFF& _CPD_OFF& _LVP_OFF& _BODEN_OFF& _PWRTE_ON& _WDT_OFF& _XT_OSC
org 0x00
temp1 equ 20h ;for delay
temp2 equ 21h ;for delay
SwUp equ 22h ;
SwDwn equ 23h ;
units equ 24h ;
tens equ 25h ;
Sw_Flag equ 26h ;
status equ 0x03
adcon equ 0x1F
ADCON1 equ 0x9F
rp1 equ 0x06
rp0 equ 0x05
portA equ 0x05
portB equ 0x06
portC equ 0x07
option_reg equ 0x81
;****************************************************************
;Beginning of program
;****************************************************************
goto SetUp ;goto SetUp
;****************************************************************
;* Delay 10mS 10 x 1,000uS *
;****************************************************************
D_10mS movlw 0Ah
movwf temp2
D_a nop
decfsz temp1,1
goto D_a
decfsz temp2,1
goto D_a
retlw 00
;****************************************************************
;* port A and B initialisation *
;****************************************************************
SetUp bsf STATUS,RP0
movlw b'00000000' ;turn portB all outputs connected to 7segments
movwf TRISB
movlw b'00000011' ;turn portC 0,1 as inputs 2,3 as outputs to drive the segments
movwf TRISC
bcf STATUS,RP0
clrf portB
clrf units
clrf tens
clrf Sw_Flag
goto Main
Up btfsc Sw_Flag,2
retlw 00
bsf Sw_Flag,2
incf units,1
movlw 0Ah ;put 10 into w
xorwf units,0 ;compare units file with 10
btfss status,2 ;zero flag in status file. Will be set if units is 10
retlw 00
clrf units
incf tens,1
movlw 0Ah ;put 10 into w
xorwf tens,0 ;compare units file with 10
btfsc status,2 ;zero flag in status file. Will be set if tens is 10
clrf tens
retlw 00 ;display passes 99 but not below 0
Dwn btfsc Sw_Flag,3
retlw 00
bsf Sw_Flag,3
decf units,1
movlw 0FFh ;put FFh into w
xorwf units,0 ;compare units file with FFh
btfss status,2 ;zero flag in status file. Will be set if units is 10
retlw 00
movlw 09
movwf units ;put 9 into units file
decf tens,1
movlw 0FFh ;put 0FFh into w
xorwf tens,0 ;compare tens file with 0FFh
btfsc status,2 ;zero flag in status file. Will be set if tens is 0FFh
goto $+2 ;tens file is 0FFh
retlw 00
clrf tens
clrf units
retlw 00 ;display not below 0
Main btfss portC,0 ;test switch-press for UP
call Up ;UP switch pressed
btfss portC,1 ;test switch-press for Down
call Dwn ;Down switch pressed
movlw b'00000100' ;Make RC2 HIGH for units drive
movwf portC
movf units,0 ;copy unit value into w
call table ;unit display value will return in w
movwf portB ;output units value
call D_10mS ;call delay
clrf portB ;clear display
movlw b'00001000' ;Make RC3 HIGH for tens drive
movwf portC
movf tens,0 ;copy tens value into w
call table ;tens display value will return in w
movwf portB ;output tens value
call D_10mS ;call delay
clrf portB ;clear display
btfsc portC,0 ;bit will be zero when sw is pressed
bcf Sw_Flag,2
btfsc portC,1 ;bit will be zero when sw is pressed
bcf Sw_Flag,3
goto Main
table addwf PCL,F ;02h,1 add W to program counter
retlw b'00111111' ; "0" -|F|E|D|C|B|A
retlw b'00000110' ; "1" -|-|-|-|C|B|-
retlw b'01011011' ; "2" G|-|E|D|-|B|A
retlw b'01001111' ; "3" G|-|-|D|C|B|A
retlw b'01100110' ; "4" G|F|-|-|C|B|-
retlw b'01101101' ; "5" G|F|-|D|C|-|A
retlw b'01111101' ; "6" G|F|E|D|C|-|A
retlw b'00000111' ; "7" -|-|-|-|C|B|A
retlw b'01111111' ; "8" G|F|E|D|C|B|A
retlw b'01101111' ; "9" G|F|-|D|C|B|A
end
Main2 clrf portC
btfss portC,0
call on1
BTFSS portC,1
call on2
goto Main2
on1 movlw b'00001000'
movwf portC
retlw 0x00
on2 movlw b'00000100'
movwf portC
retlw 0x00
=janosandi;
& its done Now lets move to the main problem
in the code which i've included before i have a 2 digits counter which its working on 16f628
why its not working with 16f877 ? at the start r the files at 20h to 26h free to use for variables?
any idea will help
thx guys
im using 4mhz Crystal & other functions is working great
i just want to convert the pic16f628 code into 16f877
just converted the ports i thing there is something else with the registers which i've used for variables
or if u have 2 segments counter ready for this will b great
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?