| View previous topic :: View next topic |
| Author |
Message |
Tester21 Guest
|
|
Posted: Wed May 18, 2005 8:44 am |
|
|
OK. I will try your code today!.
Do you have some example for pull down switch and what is the whole story about pull down switch ? How is this working ( on programmer side) ?
Thank you. |
|
 |
DragonPIC
Joined: 11 Nov 2003 Posts: 118
|
|
Posted: Wed May 18, 2005 10:04 am |
|
|
Sounds like you need to buy a book. In your circuit you previously posted you have a resistor pulling the signal up to 5V. This high state causes the PIC to read this input as a 1 in digital code. When you push the switch into the closed position, the signal is then grounded to make (pull) the input to 0V. This low state is read as a 0 in digital code.
PIC ports can be set as inputs or outputs depending on register settings. So in order to read the state of the pin, the pin must be configured as an input (set_tris_a(0x08); //0x08 = 00001000 - 1 = input and 0 = output).
Some ports are multifunctional. Port A, for instance, may be used as an ADC input (analog to digital converter used to convert an analog voltage level into a digital code). If you are using these pins to determine a digital state you must make sure the port is configured to do so. If you are using the CCS wizard, the wizard may usually set this up for you.
The thing about programming microcontrollers is that you usually need a good understanding of both hardware and software. It's not like a PC where everything is handled by the OS and the already created drivers for the devices you are using. So recommended reading here would be a C programming book, a PIC datasheet (and the PIC midrange referrence all downloadable off microchip website), and a some electronics books (basic electronics and a digital/micro electronics book). Sometimes much of this information can be found in one book. Goto amazon.com and type in PIC programming (or a variety of key words describing what you want to learn) and many books should come up.
Expecting people in forums to do this work for you isn't a good way to go. It is hard for me to know exactly how experienced you are and how much knowledge you actually have wth micros. Much of the information presented in this forums is NOT "how to program in C" or "how to use a PIC" topics. They are "how do I do a specific thing in CCS C (compared to other ANSI C compilers)" or "how would you code this for a specific project" or "this CCS device driver isn't working right" and sometimes "I don't get how a timer works", ect.. At least when someone asks questions I expect them to have some grasp of knowledge of what they are doing.
To add, check out "Nuts and Volts" magazine at nutsvolts.com. They always have PIC articles in there for beginners to advanced.
You still din't answer my question about the debugger. If you don't have one, you should get one. If you don't know how to use one, learn. I makes figureing out whats wrong a LOT easier. Don't walk into a problem blindly. Find out exactly what the PIC is doing. _________________ -Matt |
|
 |
Tester21 Guest
|
|
Posted: Wed May 18, 2005 11:36 am |
|
|
I have in circuit debugger 2 from microchip and one target board connected thru ICD connector ( power comes from programmer ).
I use ICD2 as debugger and as programmer ...
On this target board i have those buttons described before. One pull up and one pull down... |
|
 |
Guest
|
|
Posted: Wed May 18, 2005 12:17 pm |
|
|
| Tester21 wrote: | I have in circuit debugger 2 from microchip and one target board connected thru ICD connector ( power comes from programmer ).
I use ICD2 as debugger and as programmer ... |
Good, can you look in the port A register and see the value of pin A3? You read this value from register address 0x05 and is a hex value.
| Tester21 wrote: |
On this target board i have those buttons described before. One pull up and one pull down... |
OK, I see two diagrams posted before. 1 from a guest and 1 from you. You have both of those connected to the same pin? You should be using either one or the other on a pin. NOT both on the same pin. (well if the one by the guest has no resistor, you shouldn't be using that one at all. You would short out the power supply. The resistor is there to limit the current to the input and to prevent a direct short between power and ground.) Use the one posted under your name with the last code I posted. |
|
 |
DragonPIC
Joined: 11 Nov 2003 Posts: 118
|
|
Posted: Wed May 18, 2005 12:20 pm |
|
|
sorry, that last post was from me. I guess the forum logs you out after you idle for too long. _________________ -Matt |
|
 |
Guest
|
|
Posted: Thu May 19, 2005 2:46 pm |
|
|
| Quote: |
Good, can you look in the port A register and see the value of pin A3? You read this value from register address 0x05 and is a hex value. |
Sorry to ask such dumb question, but where can i see this ?
Im using MPLAB 7.11
p.s. im using two different pins for switches. |
|
 |
Tester21 Guest
|
|
Posted: Tue May 31, 2005 5:59 am |
|
|
finaly... there was problem with debouncing ( as far as i can tell ).
It looks like there is still some problem with interrupt.
The program will jump out from loop ( before end of time ) but not allways.
Sometimes you can press and press and press but nothing happens and sometimes its working ok ?? I have tested different states ( short, longer press ) but the problem is same. Port setting are correct...
I put another ( longer ) counter direct after the first and i get totaly same action. Sometimes you can jump out and sometimes you have to wait till the count is over. |
|
 |
Tester21 Guest
|
|
Posted: Thu Jun 02, 2005 3:25 am |
|
|
| Can anyone help with this ? |
|
 |
|