![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
actually I just took a look at my other 16f690 program code. This is for the counter that I made, which works flawlessly. But I had declared some critical values starting in the 0xC1 range! I am assuming that it only worked because the variables managed to fall somewhere in the GPR range.
I will be reading up on how to use the simulator tonight. I just tested the PIC in the other project, and it works fine. ARG!!!!!!! I am going to have to go line by line and check to see if I accidentally deleted something. MPLAB was behaving oddly the other night...When I clicked on a line it would paste code from somewhere and kept putting breaks in spots.... Last edited by Ambient; 3rd February 2008 at 11:42 PM. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Unless I'm blind
__________________
Superman returns..
|
||
|
|
|
|
|
(permalink) |
|
You need to enable global interrupts (INTCON,7) for any interrupts to work. Also, are you using (corrupting) temp in your table call? And, as already mentioned you aren't saving W in your ISR.
Mike. Edited as I didn't look at all the code. Last edited by Pommie; 4th February 2008 at 02:30 AM. |
|
|
|
|
|
|
(permalink) |
|
hmmm i guess i wasn't. Thats the last time I copy code from another project. I did not need to save W in my last project, and I recycled some of its code.
GIE was disabled while I tried to figure out why the pins were screwy. I just had the program send a digit manually in the main function. temp is not used anywhere else except for when separating each nibble. I should have just named it "data" or whatever. The program is doing things in a unorganized way because I started it using IOC. When IOC generated an interrupt, it would run "ReadPort" subroutine, but now it is just set up to read when it switches displays. |
|
|
|
|
|
|
(permalink) |
|
fixed another issue. It turns out that the last bank switch, which was labeled Bank 0, was actually switching to Bank 1. So writing to PORTC was not working. But it was somehow working with that error before today lol. I should not have any more problems, and I will post the end results when they are workin.
Right now the code seems to work better. It displays the test digit sent in main and then half a second later it displays what is on the input port. But it gets stuck there. I will keep working on it. Thanks guys. Code:
main bsf INTCON,GIE bsf PORTB,h'04' bcf PORTB,h'05' movlw b'11110100' ;test movwf PORTC nop nop goto $-1 ;idle loop ReadPort movf PORTB,W andlw b'11000000' iorwf PORTA,W movwf temp ;temp contains full input byte andlw h'0F' ;Least Significant Nibble call Table movwf Digit2 swapf temp,W andlw h'0F' ;Most Significant Nibble call Table movwf Digit1 Display1 call ReadPort bsf PORTB,h'04' ;disable display 2 movf Digit1,W movwf PORTC bcf PORTB,h'05' ;enable display 1 goto STATUS_RESTORE Display2 bsf PORTB,h'05' ;disable display 1 movf Digit2,W movwf PORTC bcf PORTB,h'04' ;enable display 2 goto STATUS_RESTORE Table andlw b'00001111' addwf PCL,F ;PORTC 76543210 ;Segment abcdefgh, active low retlw b'00000010' ;0 retlw b'10011110' ;1 retlw b'00100100' ;2 retlw b'00001100' ;3 retlw b'10011000' ;4 retlw b'01001000' ;5 retlw b'01000000' ;6 retlw b'00011110' ;7 retlw b'00000000' ;8 retlw b'00011000' ;9 retlw b'00010000' ;A retlw b'11000000' ;B retlw b'01100010' ;C retlw b'10000100' ;D retlw b'01100000' ;E retlw b'01110000' ;F END Last edited by Ambient; 4th February 2008 at 09:06 AM. |
|
|
|
|
|
|
(permalink) |
|
Your ReadPort routine seems to have lost it's return instruction.
Mike. |
|
|
|
|
|
|
(permalink) |
|
hmmm..that might be important lol. TY now it works perfectly, just gotta adjust the PS for TMR2 and maybe reorganize the code. It is not very efficient right now.
Last edited by Ambient; 4th February 2008 at 08:32 PM. |
|
|
|
|
|
|
(permalink) |
|
Changing banks by doing this:
Code:
movlw b'00111000' movwf STATUS ;BANK 1 movlw b'01000001' movwf OSCCON ;sets oscillator to 1MHz Why not use the banksel directive? Like this: Code:
banksel OSCCON ;bank 1 movlw b'01000001' movwf OSCCON ;sets oscillator to 1MHz
__________________
========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 5th February 2008 at 01:15 AM. |
|
|
|
|
|
|
(permalink) |
|
True. And the code would be a little more portable for different 16f's too. I already have it posted in the projects forum, I will mod the code there.
|
|
|
|
|
|
|
(permalink) |
|
Here's another thing you're doing that could (should?) be done differently. Your code has this
Code:
w_temp EQU 0x40 ; variable used for context saving status_temp EQU 0x41 ; variable used for context saving pclath_temp EQU 0x22 ; variable used for context saving Digit1 EQU 0x43 Digit2 EQU 0x44 temp EQU 0x45 Why not use a cblock instead? Easier to type. Easier to read. Code:
cblock 0x20 w_temp,status_temp,pclath_temp,Digit1,Digit2,temp endc Code:
cblock 0x20 w_temp,status_temp,pclath_temp Digit1,Digit2,temp endc Code:
cblock 0x20 w_temp status_temp pclath_temp endc
__________________
========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 5th February 2008 at 11:45 PM. |
|
|
|
|
|
|
(permalink) |
|
When using cblock you can also set the variable size,
Code:
cblock 0x20 Accumulator:2 CharBuffer:8 TimeBuffer:0 Seconds Minutes Hours ;etc endc Mike. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
========================= Futz's Microcontrollers & Robotics ========================= |
||
|
|
|
|
|
(permalink) |
|
Thanks guys. When I was starting out programming I avoided using cblock and banksel and others like it. I felt that I should do things manually so that I understood everything that was happening. But now I guess I should start using them.
|
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Quik PIC Programming kit | Krumlink | General Electronics Chat | 5 | 27th January 2008 11:27 PM |
| Capturing and reproducing audio with a PIC | Fred.Amoson | Micro Controllers | 14 | 14th December 2007 08:21 PM |
| Problems switchin relay with PIC | Andy1845c | General Electronics Chat | 5 | 17th November 2007 06:13 PM |
| High ADC sampling rate PIC, 18F needed? | bananasiong | Micro Controllers | 24 | 28th October 2007 12:13 PM |
| Four PIC with One LCD.. | meera83 | Micro Controllers | 13 | 20th September 2007 06:40 AM |