![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #16 |
|
if using data db 0x01, 0x02, 0x03 so how am i gonna read the databyte? thank you | |
| |
| | #17 |
|
You can't, you have to use a sequence of retlw instructions. Tha data instruction is to place values in EEPROM. Mike. | |
| |
| | #18 |
|
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 thank you. | |
| |
| | #19 |
|
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 | |
| |
| | #20 |
|
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. | |
| |
| | #21 |
|
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. | |
| |
| | #22 |
|
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. | |
| |
| | #23 |
|
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 ... 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. | |
| |
| | #24 |
|
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. | |
| |
| | #25 |
|
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. | |
| |
| | #26 |
|
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. | |
| |
|
| 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 |