picaboo
Newbie
Offline
Posts: 12
Thank You
-Given: 11
-Receive: 0
|
|
« on: April 16, 2010, 12:11:17 12:11 » |
|
Hello Everybody,
This seem to be awfully simple, but I am not able to get it working.
I am working with a PIC16F877A, sitting on a ICD2 target board. I am using Hi-Tech suit (picc). In the project, I am using ICD2 as a debugger.
I am using only 1 pin of this huge PIC. A 4K7 resistor is connected between RB0 and +5V as a pullup. I am not using PORTB's internal pullups.
I have a multimeter probe touching RB0. Please see the code below. What I am expecting is that after reset, the multimeter should show +5V (high). After executing the line "TRISB &= ~(1<<HT9200_CE);" in HT9200_enable routine, the multimeter should show 0V (low).
What I am seeing is, the RB0 value stays high. After the program execution finishes, if I disconnect the 4K7 resistor from RB0, it still stays high. I don't understand this. At that point TRISB[0] is 0 (output) and I had loaded RB0 latch with 0 before. So, the RB0 should be driven low.
I also observed the following.
1. If I disconnect the 4K7 resistor and then reset the PIC, the RB0 shows 0V. This is also mystery to me. After reset all IO pins become input and floating. So, the voltage should be near to 2.5V, isn't it? Why is it showing logic low?
Appreciate if you can help me figuring out why this simple pull up experiment is not working.
--Picaboo
Code ====
#include <htc.h>
#define HT9200_CE 1 #define HT9200_CLK 0 #define HT9200_DATA 2
__CONFIG(XT & WDTDIS & PWRTDIS & BORDIS & LVPDIS & WRTEN & DEBUGEN & DUNPROT & UNPROTECT);
void HT9200_Init(void) { //Pull CE, CLK and DATA high //The CE, CLK and DATA does not have pullups. These are driven by master. //At power-up, all ports come up as I/P. These pins are inputs to the //HT9200 also. So, at power-up these pins does not have any driver.they //float. The floating pin may cause HT9200 interpret the input as valid something //and play the frequencies. //To make the CE pin high (which makes HT9200 inactive) at power up, and since //all pins come up as input which floats, there is a pull up on this pin. So, at //power up this pin is seen as high and HT9200 does not play any tone. //To control the CE pin, only low state need to be driven by PIC. The port latch //is always loaded with zero. Whenever low is needed TRISB is programmed to make //this pin output, and the pin goes low. Whenever high is needed, TRISB is //programmed to make the pin input, and the pullup causes the pin to go high.
//Clock and data pin is completely driven by PIC since there is no pullup. //These pins are always configured as output. //The Pin latches must be loaded with 'high' before making the pin direction //as output (by programming TRIS register). This will cause the the bus to go //to high from float. //Though at power up or at reset the pin autotomatically becomes input, just //as a precautionary measure, make CE input. The pin goes high because of pullup. TRISB |= (1<<HT9200_CE); //load 0 to CE latch PORTB &= ~(1<<HT9200_CE); //load 1 to CLK latch PORTB |= (1<<HT9200_CLK); //configure CLK pin as output TRISB &= ~(1<<HT9200_CLK); //load 1 to DATA latch PORTB |= (1<<HT9200_DATA); //configure DATA pin as output TRISB &= ~(1<<HT9200_DATA); }
//HT9200 is enabled by pulling CE low. After that wait 10ms for the osc to stabilize void HT9200_Enable(void){ unsigned short i;
//activate the bus by pulling CE low. TRISB &= ~(1<<HT9200_CE); //wait for 10ms //DelayMs(10); //DelayBigUs(10000); }
void chip_init(void) { //Timer1 overflow bit interrupt disable PIE1 = 0b00000000;
//Disable peripheral interrupt bit (Timer1 is part of periperals)) INTCON = 0b00000000;
//Disable PORTB pull_ups OPTION = 0b10000000;
// port directions: 1=input, 0=output TRISA = 0b00000000; //PortA bit 3:0 are outputs for LED cathods. bit 5 is for colon TRISC = 0b00000000; //PortC
PORTC = 0b00000000;
//Disable timer1, internal clock source, do not sync to ext clock, //shutoff osc, 1:1 prescale //T1CON = 0b00000101; T1CON = 0b00000100;
//To make RA4 digital output CMCON = 0b00000000;
PORTA = 0b00000000; }
void main(void){ chip_init(); HT9200_Init(); ei(); HT9200_Enable(); }
|