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.

Do Interrupt and LCD at the same time

Status
Not open for further replies.

metals

Junior Member level 2
Joined
Jan 25, 2011
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,441
Hi!

The problem is..

I want this program to flash the LEDs on Port C. At the break from RB0 (falling edge) I want to write "Interrupt" on the LCD display and display it for a couple of seconds. I shall use the opportunity to have a pull-up resistors on Port B inputs.

I have this code down here but the only thing that is working is the LED lights :cry:
Can anyone see what I'm doing wrong?

Code:
List P=16F877 ;Processorangivelse
;*********************************************************
status			equ			0x03
RP0				equ			0x05			
intcon			equ			0x0b			
RB0flag			equ			0x01
opt_reg			equ			0x81			
portB			        equ			0x06	
portC			        equ			0x07
trisB			        equ			0x86
trisC			        equ			0x87
trisD			        equ			0x88
var1			        equ			0x20
var2			        equ			0x21
w_temp			equ			0x22
status_temp		equ			0x23
var3			        equ			0x24			
portD			        equ			0x08
ASCII			equ			0x25
tab_pek			equ			0x26
ganger			equ			0x27
En				equ			0x01
Z				equ			0x02
PCL				equ			0x02
Var_1			equ			0x28
Var_2			equ			0x29
;*****************************
				org			0x00
				clrf		        status			
				movlw		0x00			
				movwf		0x0A			
				goto		        init

;***********interrupt vector******************
				org			0x04
				goto		       interrupt
;************subroutines*****************
wait			        movlw		0xff			
				movwf		var2			
loop_2			movlw		0xff			
				movwf		var1			
loop_1			decfsz		var1,1			
				goto		        loop_1	
				decfsz		var2,1			
				goto		        loop_2
				return						
;*******interrupt subroutin**********************

interrupt			movwf		w_temp			
				swapf		status,0 		
				movwf		status_temp		
				movlw		0x50			
				movwf		var3
loop_3			call		        wait
				decfsz	 	var3,1
				goto		        loop_3			
				bcf			intcon,RB0flag	
				swapf		status_temp,0
				movwf		status
				swapf		w_temp,1
				swapf		w_temp,0
				retfie
;************************************************

waitms			movlw		0x0A			
				movwf		Var_2		
loop2			        movlw		0x64			
				movwf		Var_1			
loop1			        decfsz		Var_1,1			

				goto		        loop1

				decfsz		Var_2,1			

				goto		        loop2
				return
;*****************************************
init			        clrw					
				movwf		portD			
				movwf		portB			
				bsf			status,RP0		
				movwf		trisD			
				movlw		0xff
				movwf		trisB			
				bcf			opt_reg,7
				bcf			opt_reg,6		
				bcf			status,RP0		
				bsf			intcon,4
				bsf			intcon,7


				clrw						
				movwf		portD			
											
				bsf			status,RP0		
				movwf		trisD			
											
				bcf			status,RP0		
				call		        LCDinit
;**************************************************


enable			bsf			portD,En
				call		        wait
				bcf			portD,En
				call		        wait
				return
;**************************************************

main			        clrf		        tab_pek			
				movlw		0xAA
				movwf		portC
				call 		        wait
				call 		        wait
				movlw		0x55
				movwf 		portC
				call 		        wait
				call 		        wait
				goto 		        main
;**************************************************	
again		                movfw		tab_pek			
				call		        text			
				iorlw		        0x00			

				btfsc		       status,Z		
				goto		       klar			
				call		       show_lcd		
				incf		       tab_pek,f		
		                goto		       again			
klar		               	goto		        klar
text			        addwf		PCL,f			
				retlw		'I'				
				retlw		'n'				
				retlw		't'
				retlw		'e'
				retlw		'r'
				retlw		'r'
				retlw		'u'
				retlw		'p'
				retlw		't'
	
			


show_lcd		        movwf		ASCII			
				andlw		0xf0			
				movwf		portD			
				bsf			portD,0			
				call		        enable			
				swapf		ASCII,w			
				andlw		0xf0			
				movwf		portD			
				incf		        portD,f			
				call		        enable			
				return

				movlw		0x00			
				movwf		portC			
				call		        wait			
				movlw		0xff			
				movwf		portC			
				call		        wait			
				goto		        main


LCDinit			movlw		0xff			
				movwf		ganger			
loop3			        call		        waitms			
				decfsz		ganger,1			
				goto		        loop3			
				movlw		0x30			
				movwf		portD			
				call 		        enable			
				movlw		0x05
				movwf		ganger
loop4			        call		        waitms
				decfsz		ganger,1	
				goto		        loop4			

				movlw		0x30
				movwf		portD
				call		       enable			

				call		        wait		
				movlw		0x30
				movwf		portD
				call		        enable
				call		        waitms

				movlw		0x20
				movwf		portD
				call		        enable
				call		        waitms			
				movlw		0x20			
				movwf		portD
				call		        enable
				movlw		0x80
				movwf		portD
				call		        enable
				call		        waitms
				movlw		0x00			
				movwf		portD
				call		        enable
				movlw		0x10	
				movwf		portD
				call		        enable
				call		        waitms
				movlw		0x00			
				movwf		portD
				call		        enable
				movlw		0x60
				movwf		portD
				call		        enable
				call		        waitms
				movlw		0x00			
				movwf		portD
				call		        enable
				movlw		0xe0
				movwf		portD
				call		        enable
				call		        waitms
				return

;************************lcd_clear**********************
lcd_clear		        movlw 		 0x00 				
				movwf		portD
				call 		        LCD_Enable
				movlw		0x10
				movwf 		portD
				call		        LCD_Enable
				return


;************************LCD_Enable*************************
LCD_Enable 		bsf 		portD,En 			
				call 		loop1
				bcf 		portD,En 			
				call		loop1
				return


				end
 

Hi!

Can anyone see what I'm doing wrong?



Hi,


Well a good try, but you have quite a few errors to sort out.

What you are looking to do is a staight forward task but its perhaps a lot all together if its your first attempt; have you tested simpler routines like a led flasher before ?


I have not run your code, though it does build ok, but here are some areas you need to look at.


You have specified many of the System Registers such as Ports and PCL etc.
No need to do that if you use this code after your LIST statement.
#include <p16F877.inc>
You still need to specify your User registers

After Org 0x000 you use several instructions before the Interrupt Vector 0x004, if you add anymore instructions at that point it will overflow into the ISR routine at 0x004 - much better to just use GOTO INIT after 0x000

On the 16F877 the Interrupt need to have whats called Context Saving - you need to see the datasheets for the examples of how to do that - without it the ISR will not work.

Have you written the lcd routine yourself ? - does it work ? - its a complex bit of programming. Also have you checked the Waits / Delays give the correct timings ?

Check those points out and then give it another try - are you using hardware or Simutlators ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top