![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
I am facing some problem while reading input through PORTB in 16F72 PIC. I wrote a simple code which shows a number between 0-9 in a seven-segment. When i press button connected to RB5, then number should increment to a different number. It works fine in Simulator. But when I tried in PIC, it shows digit 8, and have a flickering too.... Below given is my source code written in HiTech C. Please help. I am stuck with this problem for a long perios.... ![]() //include file #include <pic.h> //16F72 configuration word according to the features required. __CONFIG(0x3FB1); int i; // This macro is to make a delay after showing a digit in a segment. #define my_delay() for ( i = 0; i <= 20; i++ ); void showNumber ( unsigned char *num ) { switch ( (*num) ) { case 0: PORTC = 0b11111100; PORTB = 0b00000000; break; case 1: PORTC = 0b00011000; PORTB = 0b00000000; break; case 2: PORTC = 0b01101100; PORTB = 0b00000001; break; case 3: PORTC = 0b00111100; PORTB = 0b00000001; break; case 4: PORTC = 0b10011000; PORTB = 0b00000001; break; case 5: PORTC = 0b10110100; PORTB = 0b00000001; break; case 6: PORTC = 0b11110100; PORTB = 0b00000001; break; case 7: PORTC = 0b00011100; PORTB = 0b00000000; break; case 8: PORTC = 0b11111100; PORTB = 0b00000001; break; case 9: PORTC = 0b10111100; PORTB = 0b00000001; break; case 10: PORTC = 0b0; PORTB = 0b0; PORTA = 0b0; break; } } //main function void main ( void ) { unsigned int noShow = 10; unsigned int temp = 0; unsigned long swith_1_Count = 0; unsigned int flag1 = 0; TRISB = 0b00100000; TRISA = 0x00; TRISC = 0x00; PORTC = 0; PORTB = 0; PORTA = 0; while ( 1 ) { if ( ( PORTB & 0b00100000 ) == 0b00100000 ) { temp = ( temp +1 ) % 10; } PORTA = 0b00000001; showNumber(&temp); my_delay(); } } | |
| |
| | #2 |
|
I would guess that it is showing all numbers very fast and so it looks like an 8. Try increasing your delay lots. Also, use the correct labels for the config. No one knows what CONFIG(0x3FB1); does. Mike. | |
| |
| | #3 |
|
Thanks for your reply.. Its not showing all numbers very fast. even if i increase my delay it seems to be like that... But still according to the source code, how will it behaves like this? | |
| |
| | #4 |
|
Now here one basic doubt... Can i use some of the pins in PORTB as Input and some of the pins in PORTB as output at the same time?... This problem happens when i am doing so... Please help | |
| |
| | #5 |
|
Yes, you can set any combination of input/output. Mike. | |
| |
| | #6 | |
| Quote:
Last edited by eng1; 14th November 2009 at 11:10 AM. | ||
| |
| | #7 |
|
Hi eng1, thanx for your reply. I am new to PIC. Can u brief on wat is software de-bouncing or could pls give any link abt this... ?
| |
| |
| | #8 |
|
Each time a button is pressed (or released), this doesn't result in a clean transition from Vdd to GND (from GND to Vdd). Lots of transitions between the two states happen for millisenconds. Since the PIC run fast, it could read this 'noise', causing unpredictable behaviour. De-bouncing allows you to interpret the change in switch state correctly. With the most basic implementation in software, you check the switch and when its state has changed, you generate a 20 ms delay (this is considered enough for most switches); then, you check again the state of the switch (assuming that it's staying in the same state), and take actions accordingly. Since you have already a delay elsewhere in your code, that might work if it is increased to about 20 ms; how much delay do you have now? Code: if ( ( PORTB & 0b00100000 ) == 0b00100000 ) Last edited by eng1; 14th November 2009 at 06:01 PM. | |
| |
|
| Tags |
| 16f72, input, problem, reading |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| reading an input | hobby_85 | Micro Controllers | 11 | 18th August 2009 03:23 AM |
| 18F4431 - RC6 not reading the input | atferrari | Micro Controllers | 4 | 25th May 2009 12:41 PM |
| problem reading diagram | wjyates | General Electronics Chat | 6 | 24th May 2009 08:21 PM |
| a Problem with Reading a Circuit!! | Muhammad89 | General Electronics Chat | 17 | 23rd August 2008 10:34 PM |
| PIC16F84A Reading input | mouse9911 | Micro Controllers | 2 | 23rd May 2007 03:15 AM |