Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 8th January 2009, 08:28 AM   #16
Default

if using

data db 0x01, 0x02, 0x03

so how am i gonna read the databyte?

thank you
simpsonss is offline  
Old 8th January 2009, 08:35 AM   #17
Default

You can't, you have to use a sequence of retlw instructions. Tha data instruction is to place values in EEPROM.

Mike.
Pommie is online now  
Old 8th January 2009, 09:18 AM   #18
Default

hi
Code:
		list	p=16F877A
		#include <p16F877A.inc> 

		__config _XT_OSC & _PWRTE_OFF & _WDT_OFF &_LVP_OFF 

		var1	EQU		0x0F

		org		0x00
		goto	        Main
		org		0x04
		goto	       T0_INT
		
Main
		bsf		STATUS,RP0	;switch 2 bank1
		clrf	       TRISB
		movlw	b'00000111'
		movwf	OPTION_REG
		bcf		STATUS,RP0	;switch 2 bank0
	
		movlw	0xe8
		movwf	TMR0
		bsf		INTCON,T0IE	;enable timer interrupt
		bsf		INTCON,GIE
		clrf	        PORTB		;clear PORTB
		goto	$


T0_INT
		
		bcf		INTCON,T0IF	;clear int flag		
		movlw	0xe8
		movwf	TMR0
		bsf		var1,1
		movf	        var1, PORTB

		retfie
i'm wonder why my var1 register is not working. i cant get logic 1 for PORB.0.

thank you.
simpsonss is offline  
Old 8th January 2009, 12:43 PM   #19
Default

Well, I can see a couple of things wrong with your code,

var1 EQU 0x0F

this is not good because 0x0f is the location of TMR1H. The area you should use for your variables is 0x20 onward.

movf var1, PORTB

This is not a valid instruction (and should be an error in MPLAB). What you need to do is,
Code:
	movf	var1,w		;move var1 to W
	movwf	PORTB		;move W to portb
Mike.
Pommie is online now  
Old 8th January 2009, 02:05 PM   #20
Default

haha icic.. what a fool mistake i had made. huh~

but when i compile MPLAB doesnt show any error.haha..

thank you.

since 16f877a have an external interrupt for RB0. And it has and state change for RB7:RB4. so izzit mean that whenever there is either a low to high or vice versa state, it will set the flag bit? So after the flag is set, can i know which pin is being changed? because i'm planing to have two external interrupt button. but seems like we only have one RB0 ext interrupt pin.

thank you.

Last edited by simpsonss; 8th January 2009 at 02:07 PM.
simpsonss is offline  
Old 8th January 2009, 02:37 PM   #21
Default

If you explain what you are trying to achieve it will be easier to advise.

However, if you use the port B change interrupt then you need to keep a record of the previous state so you know which pin changed. Doing port xor previousState will give you the bits that have changed.

Mike.
Pommie is online now  
Old 9th January 2009, 01:01 AM   #22
Default

ok this is my plan. i have two external push button. For push button_1, when i press it it will be doing task1 and for push button_2 when i press it, will be doing task2. because both push button also have to be an external interrupt. So i'm curious where to place the second push button since 16f877a only has a external interrupt pin which is RB0.

can u get my idea?So i plan to use the change state of RB7:RB4 to know between this two external interrupt i know which button i pressed.

thank you.
simpsonss is offline  
Old 9th January 2009, 01:47 AM   #23
Default

This is fairly simple to do as long as you keep a copy of the previous state.

Code:
	movfw	PORTB
	xorwf	Previous,W	;W=changed pins
	xorwf	Previous,F	;previous=PortB
	andwf	Previous,W	;w=new presses
	movwf	NewKeys
	btfsc	NewKeys,7
	goto	Key7Pressed
	...
NewKeys will have a bit set for every pin that went from 0 to 1.

If your keys are active low then insert an xorlf 0xff after the load from the port.

Edit, I should point out that the above code works much better on a 10mS interrupt due to problems with key bounce when using interrupt on change.

Mike.

Last edited by Pommie; 9th January 2009 at 02:21 AM.
Pommie is online now  
Old 9th January 2009, 05:43 AM   #24
Default

hi pommie,
since only RB7:RB4 have the change state function. so when i do i need to clear the lower byte of portb? because i'm using portb.0 also.And the 'Previous' in your coding izzit i need to assign 0x00 to it, so that there is value in previous.

thank you.
simpsonss is offline  
Old 9th January 2009, 06:18 AM   #25
Default

I would just use a timer interrupt to read your keys. Your 6mS interrupt would work quite well. Doing it this way you can use as many bits of port B as you wish and you can have a completely separate interrupt for RB0. Yes, Previous should be initiated to zero.

Mike.
Pommie is online now  
Old 9th January 2009, 07:26 AM   #26
Default

hi pommie,
my 6ms already used to do its task something like blink the led. So i try to add in the code to check my push button evry 6ms interrupt. but for my push button i have a nested loop to check how many times i have pressed the push button. because different push number will have different task to do.

So when i test on the code.i found that, i need to press quite long time to let the system know the push button has been pressed .and let say when i push the second time i want the system to do another task. but , final result is when i just push once the system already go to the push twice task. So i think it should be the debounce problem. So i decided to use the change port function of portb.

am i choosing the correct way?

thank you.
simpsonss is offline  
Reply

Tags
facing, problem, timer0

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Timer0 problem littletransistor Micro Controllers 8 27th November 2008 06:55 AM
LCD & CHECK CODE (facing problem) smileguitar Micro Controllers 17 20th March 2008 05:30 PM
Problem in LED Flasher in pic 16F877A rakan Micro Controllers 6 7th April 2007 11:45 AM
info about computes im facing some hardware problem salman007 Chit-Chat 6 29th March 2007 07:23 PM
XTAL Problem in PIC 16F877A Hesam Kamalan Micro Controllers 7 16th July 2006 07:41 PM



All times are GMT. The time now is 03:47 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker