Hi, this is my first post. I'm new to programming and micro controllers but have started using a few PIC's with MPLAB X and the HITEC C version9..? something compiler.
This is only a query as I would like to know why I'm getting this particular behaviour which I will try to explain. I'm using a 16F690 PIC on a low pin count board and a pickit 2 programmer.
I also made myself a hardware tfla-01 logic analyzer, the design with it's own power and resistors and an isolating chip. I made it a little while ago so can't remember details but it's not relevant to my question.
I read an article about left shifting a binary and OR' ing it with the port register to turn pins high and AND'ing a two's complimented version for low. I have walked the below code through using MPLAB's simulator. Viewing the PORTC register contents goes like I would have thought it should.
PORTC
starts 000000 ...→ 000001 → 000011 → 000111 → 001111 → 001110...[the final &=~]
Also when I use the software logic analyzer in the simulator to trace RC0-RC3 they go up as I would expect consistent with the above. What should happen then is rc0 goes up, then rc1..rc2..rc3.
Then rc0 should go low.. this loops so rc0 toggles of and on but the other pins stay high.
Now I program my PIC and get each led light in sequence from rc0 to rc3 turn on individually.
When I trace using the hardware tfla-01 analyzer this confirms after each shift operation only the shifted bit brings that pin high, the other 1's that remain in the PORTC register don't keep their respective pins high. The time delay between shifts is set to 500ms. Code snippet below.
Portc set for ouput and initialized all pins low...+ #define delay 500
...
PORTC|=(1<<0);//enable rc0 - zero shift 1 then OR with portc register
__delay_ms(delay);
PORTC|=(1<<1);//rc1 up
__delay_ms(delay);
PORTC|=(1<<2);//rc2 up
__delay_ms(delay);
PORTC|=(1<<3);//rc3 up
__delay_ms(delay);
PORTC&=~(1<<0);//disable rc0
__delay_ms(delay);
...loops
So my query is why when bit's are set to 1 in the PORTC register do they not hold the pin high. They only hold the individually shifted bit place pin high, the rest go low. The 16F690 does not support in circuit debugging without a header so I can't know that on the chip this is also the case and it may differ from the simulated register.
I'm aware that the software simulation is just that already after trying to trace clkout signal, this signal does not exist on the simulator but does when using the chip.
This may be very obvious to someone with more experience but at this time of writing I would have thought all 1's in the register would keep the pinouts high.
Any explanations welcomed.
Doug.
This is only a query as I would like to know why I'm getting this particular behaviour which I will try to explain. I'm using a 16F690 PIC on a low pin count board and a pickit 2 programmer.
I also made myself a hardware tfla-01 logic analyzer, the design with it's own power and resistors and an isolating chip. I made it a little while ago so can't remember details but it's not relevant to my question.
I read an article about left shifting a binary and OR' ing it with the port register to turn pins high and AND'ing a two's complimented version for low. I have walked the below code through using MPLAB's simulator. Viewing the PORTC register contents goes like I would have thought it should.
PORTC
starts 000000 ...→ 000001 → 000011 → 000111 → 001111 → 001110...[the final &=~]
Also when I use the software logic analyzer in the simulator to trace RC0-RC3 they go up as I would expect consistent with the above. What should happen then is rc0 goes up, then rc1..rc2..rc3.
Then rc0 should go low.. this loops so rc0 toggles of and on but the other pins stay high.
Now I program my PIC and get each led light in sequence from rc0 to rc3 turn on individually.
When I trace using the hardware tfla-01 analyzer this confirms after each shift operation only the shifted bit brings that pin high, the other 1's that remain in the PORTC register don't keep their respective pins high. The time delay between shifts is set to 500ms. Code snippet below.
Portc set for ouput and initialized all pins low...+ #define delay 500
...
PORTC|=(1<<0);//enable rc0 - zero shift 1 then OR with portc register
__delay_ms(delay);
PORTC|=(1<<1);//rc1 up
__delay_ms(delay);
PORTC|=(1<<2);//rc2 up
__delay_ms(delay);
PORTC|=(1<<3);//rc3 up
__delay_ms(delay);
PORTC&=~(1<<0);//disable rc0
__delay_ms(delay);
...loops
So my query is why when bit's are set to 1 in the PORTC register do they not hold the pin high. They only hold the individually shifted bit place pin high, the rest go low. The 16F690 does not support in circuit debugging without a header so I can't know that on the chip this is also the case and it may differ from the simulated register.
I'm aware that the software simulation is just that already after trying to trace clkout signal, this signal does not exist on the simulator but does when using the chip.
This may be very obvious to someone with more experience but at this time of writing I would have thought all 1's in the register would keep the pinouts high.
Any explanations welcomed.
Doug.