[PIC] Alarm clock and temperature using PIC16f877a - code ASM- 6 led 7seg

Status
Not open for further replies.

ndnhatminh

Newbie level 2
Joined
Apr 5, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
13
Hi everybody,
I'm working with a PIC 16F877a and assembly code to display alarm clock (cannot have real time) and temperature but I have some problems with buttons. It's not work.
This is my attach file include code and proteus. Please help me!
Thanks so much!
View attachment file goc.rar
 

Hi Ndnhatminh

You have made it very difficult to read your program to see what you are doing
I dont understand vietnamese. could you translate your registers to english.

Could you post your schematic here as a Jpeg so I can look at it.

We could then go through it step by step so I can help you
 


I translated code into english.
I dont know why the buttons don't work. I use 4 buttons: 'mo'=reset. 1 setup. 'tang'=increase
'giam'=decrease.
Here are ASM code and schematic
Thanks so much!


View attachment TC.rar

Code:
PROCESSOR 16F877A
INCLUDE <P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

round1  equ 0x36
count  equ 0x37
temp equ 0x20
temp1 equ 0x21
dozen_temp  equ 0x22
unit_temp  equ 0x23
hour  equ 0x24
hour1  equ 0x25
dozen_hour  equ 0x26
unit_hour  equ 0x27
minute  equ 0x28
minute1  equ 0x29
dozen_minute  equ 0x30
unit_minute  equ 0x31
seconds  equ 0x32
seconds1  equ 0x33
dozen_seconds  equ 0x34
unit_seconds  equ 0x35
count2 equ 0x38
W_save EQU 0x39
PCLATH_save EQU 0x40 
STATUS_save EQU 0x41 
FSR_save EQU 0x42

ORG 0x0000
GOTO start

; interrupt

ORG 0X0004

MOVWF W_save
SWAPF STATUS,W
CLRF STATUS
MOVWF STATUS_save
MOVF PCLATH,W
MOVWF PCLATH_save
CLRF PCLATH
MOVF FSR,W
MOVWF FSR_save


BTFSS PIR1,TMR1IF 
GOTO exit_int
BCF T1CON,TMR1ON 

CLRF TMR1L 
CLRF TMR1H 
MOVLW 0xB
MOVWF TMR1H 
MOVLW 0xDC
MOVWF TMR1L
BSF T1CON,TMR1ON 
BCF PIR1,TMR1IF 

incf count,f
movf count,w
xorlw d'1'
btfss status,z
goto exit_int

clrf count
incf unit_seconds,f
movf unit_seconds,w
xorlw d'10'
btfss status,z
goto exit_int
clrf unit_seconds
incf dozen_seconds,f
movf dozen_seconds,w
xorlw d'6'
btfss status,z
goto exit_int
clrf dozen_seconds
clrf unit_seconds
incf unit_minute,f
movf unit_minute,w
xorlw d'10'
btfss status,z
goto exit_int
clrf unit_minute
clrf dozen_seconds
clrf unit_seconds
incf dozen_minute,f
movf dozen_minute,w
xorlw d'6'
btfss status,z
goto exit_int
clrf dozen_minute
clrf unit_minute
clrf dozen_seconds
clrf unit_seconds
incf hour,f
movf hour,w
xorlw d'24'
btfss status,z
goto exit_int
clrf dozen_minute
clrf unit_minute
clrf dozen_seconds
clrf unit_seconds
clrf hour
goto exit_int

exit_int:
MOVF FSR_save,W
MOVWF FSR 
MOVF PCLATH_save,W
MOVWF PCLATH 
SWAPF STATUS_save,W
MOVWF STATUS
SWAPF W_save,1
SWAPF W_save,0

RETFIE
;
start:

; port initialization

BSF STATUS,5
bsf trisA,0
CLRF TRISc
CLRF TRISD
movlw b'00111111'
movwf trisB

BCF STATUS,5
clrf portC
CLRF PORTD

;ADC  initialization

bsf status,5
movlw b'10001110'
movwf ADCON1
bcf status,5
movlw b'10000001'
movwf ADCON0

;RBO interrupt
bsf INTCON,7
bsf INTCON,4
bcf INTCON,1

;timer1 initialization

bsf status,5
movlw b'11000000'
movwf INTCON
bsf	PIE1,0

bcf status,5
bcf	PIR1,0
movlw b'00110000'
movwf T1CON
CLRF TMR1H
CLRF TMR1L
movlw 0xB
movwf TMR1H
movlw 0xDC
movwf TMR1L
BSF T1CON,TMR1ON

; variable initialization

clrf temp
clrf hour
clrf dozen_minute
clrf unit_minute
clrf dozen_seconds
clrf unit_seconds
clrf count
;

main:

;read_adc
BSF ADCON0,GO 
BTFSC ADCON0,GO
GOTO $-1

MOVLW 0x07 
MOVWF count2
DECFSZ count2 
GOTO $-1

bsf status,5
movf ADRESL,W
bcf status,5
movwf temp
BCF	STATUS,0
RRF	temp

call display
goto main

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

display:

movf unit_seconds,w
CALL TABLE
MOVWF PORTc
movlw 0x1
movwf portd
CALL DELAY

MOVLW 0X00  
MOVWF PORTd
MOVLW 0xff 
MOVWF PORTc

movf dozen_seconds,w
CALL TABLE
MOVWF PORTc
movlw 0x2
movwf portd
CALL DELAY

MOVLW 0X00  
MOVWF PORTd
MOVLW 0xff 
MOVWF PORTc

movf unit_minute,w
CALL TABLE
MOVWF PORTc
movlw 0x4
movwf portd
CALL DELAY

MOVLW 0X00  
MOVWF PORTd
MOVLW 0xff 
MOVWF PORTc

movf dozen_minute,w
CALL TABLE
MOVWF PORTc
movlw 0x8
movwf portd
CALL DELAY

MOVLW 0X00  
MOVWF PORTd
MOVLW 0xff 
MOVWF PORTc

movf hour,w
movwf hour1
clrf unit_hour
clrf dozen_hour
a_hour:
movlw d'10'
subwf hour1,f
btfsc status,c
goto sai_hour
movlw d'10'
addwf hour1,w
movwf unit_hour
goto thoat_hour
sai_hour:
incf dozen_hour,f
goto a_hour
thoat_hour:

movf unit_hour,w
CALL TABLE
MOVWF PORTc
movlw 0x10
movwf portd
CALL DELAY

MOVLW 0X00  
MOVWF PORTd
MOVLW 0xff 
MOVWF PORTc

movf dozen_hour,w
CALL TABLE
MOVWF PORTc
movlw 0x20
movwf portd
CALL DELAY

MOVLW 0X00  
MOVWF PORTd
MOVLW 0xff 
MOVWF PORTc

movf temp,w
movwf temp1

clrf unit_temp
clrf dozen_temp
a_temp:
movlw d'10'
subwf temp1,f
btfsc status,c
goto wrong_temp
movlw d'10'
addwf temp1,w
movwf unit_temp
goto exit_temp
wrong_temp:
incf dozen_temp,f
goto a_temp
exit_temp:

movf unit_temp,w
CALL TABLE
MOVWF PORTc
movlw 0x40
movwf portd
CALL DELAY

MOVLW 0X00  
MOVWF PORTd
MOVLW 0xff 
MOVWF PORTc

movf dozen_temp,w
CALL TABLE
MOVWF PORTc
movlw 0x80
movwf portd
CALL DELAY

MOVLW 0X00  
MOVWF PORTd
MOVLW 0xff 
MOVWF PORTc

return

TABLE:
ADDWF PCL,F
RETLW 0XC0
RETLW 0XF9
RETLW 0XA4
RETLW 0XB0
RETLW 0X99
RETLW 0X92
RETLW 0X82
RETLW 0XF8
RETLW 0X80
RETLW 0X90

DELAY:
MOVLW	D'249'	
MOVWF	round1	
lap: 
NOP			
DECFSZ	round1		
GOTO	lap	
RETURN

END
 

Hi Ndnhatminh

I am battlling to see how you have connected up your switches.

assuming your switches are on port B as per your software.

You have set RB0 as your interupt as per intcon bit 4.

then immediately after that you set bit 6 and 7 and clear bit 4 ( refer to RB0 interrupt and timer 1 initialization.)

Please remember that Intcon is the same Special function register and can be addresed in any bank. but it is still just one register and not 4 separate registers.

Also remember to clear the intcon bit 1 in exit int.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…