Problem in Input /Output port

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problem in Input /Output port

8,705件の閲覧回数
pallavaggarwal
Contributor I
Sir ,
i am making a lcd display to display ac or dc voltage so for the ac/dc selection i have given an input through a jumper when the jumper is connected it ground the pin(PTB7) and when i open it it is pulled up with 10k resistor.i have used PTB0-5 for lcd (as output) and ptb7 , ptb6 as input the problem is when the jumper is not connected @ pin ptb7 the voltage shuld be 5 v approx but i m getting 2.9 volatge i dont know what is the problem, plz tell me whats the problem nothig is connected on this pin i have not used the internal pull up for this pin but a 10k pull up externally provided.
 
regards
pallav
ラベル(1)
0 件の賞賛
返信
10 返答(返信)

1,428件の閲覧回数
pallavaggarwal
Contributor I
Thanks for ur reply 
you r correctly understood but i have not initialized or using any other module on this PTB pin, i am using this for input(ptb6,7) and other ptb0-5 for output data and En, RS for lcd. i m doing nothing else i m sending u the code plz check where the problem is.
 
//Programm to display AC Voltage & Current/DC Voltage
//AC/DC Display Selection by jumper
//Voltage/Current range selection by jumpers
//onboard Reset/Mon8 connector
//PTB0-3 LCD Display data
//PTB4 Enable
//PTB5 RS
//PTB6-7Voltage range selection by jumper.

#include <hidef.h> /* for EnableInterrupts macro */
#include <MC68HC908QB8.h> /* include peripheral declarations */
 
//macro defination for PORTB out
#define setbit(A,B) A|=(1<<B)
#define clrbit(A,B) A&=~(1<<B)

void delay(unsigned int cycles)
{
 unsigned int del;
 for(del=0;del<cycles;del++);
}
void out(unsigned char lcd_data,unsigned char fl)
//fl 0 is command & 1 is data
{
 // higher nibble 1st then lower nibble
 unsigned char del;
  
 PTB = (lcd_data & 0xF0)>>4;
 
 if(fl == 1)
 setbit(PTB,5); // rs = 1;
 
 setbit(PTB,4); // en = 1;
 for(del=0;del<25;del++);//some delay
 
 clrbit(PTB,4); // en = 0;
 
 PTB = lcd_data & 0x0F;
 
 if(fl == 1) 
 setbit(PTB,5); // rs = 1;
 setbit(PTB,4); // en = 1;
 for(del=0;del<25;del++);//some delay
 
 clrbit(PTB,4); // en = 0;
 
 clrbit(PTB,5); // rs = 0;
 
 fl = 0;
 delay(300);
}
/*
unsigned int adc(unsigned char channel)
 {
  unsigned int adc_value;
  ADCLK = 0x10;
  ADSCR = channel;
  delay();
  while(!ADSCR_COCO);
  adc_value = ADRH*256 + ADRL;
  return ( adc_value );
 }
 */
void main(void)
{
 unsigned char var=0;
  delay(100);//Some initial power on delay
 CONFIG1=0x01; //disable COP
 //initialisation
 DDRB = 0x3F; // 0011 1111  
 PTB=0;//initially PTB out =0
 PTBPUE=0x00; //00 00 0000 PULL UP Disabled.
 //power up delay
 delay(10000);//500msec approx
 //main function
  
       
//initializing LCD
     //out(0x30,0);//commands
     //out(0x30,0);
       //out(0x30,0);     
     out(0x20,0);
     out(0x20,0);
      out(0x28,0);
      out(0x28,0);
      out(0x0C,0);
     out(0x06,0);
      out(0x02,0);
      out(0x01,0);  //Clear display
     
       
while(1)
 {
     //1st line code
    out(0x80,0);//Line 1 Character 1 (Position)
    
    if ((PTB & 0x80)==128)  out('D',1);//1 (if pin 7 PTB then DC Display
    else  out('A',1);//1
    
    out('C',1);//2
    out(' ',1);//3
     out('V',1);//4
     out('o',1);//5
     out('l',1);//6
     out('t',1);//7
     out(' ',1);//8
     out(' ',1);//9
     out(' ',1);//10
     out('0',1);//11
     out('0',1);//12
     out('0',1);//13
     out('.',1);//14
     out('0',1);//15
     out('V',1);//16
     
     
     //2nd line code
     
     
    
     if((PTB & 0x40)==64)//if pin PTB6 PTB then Voltage Dsplay only
      {
        out(0xC0,0);//Line 2 Character 1 (Position)
        if ((PTB & 0x80)==128)  out('D',1);//1 (if  PTB7 then DC Display
        else  out('A',1);//1
        
        out('C',1);//2
        out(' ',1);//3
         out('C',1);//4
         out('u',1);//5
         out('r',1);//6
         out('r',1);//7
         out('e',1);//8
         out('n',1);//9
         out('t',1);//10
         out(' ',1);//11
         out('0',1);//12
         out('0',1);//13
         out('.',1);//14
         out('0',1);//15
         out('A',1);//16
      }
  }
}
 

 
 
best regards
Pallav  
0 件の賞賛
返信

1,427件の閲覧回数
peg
Senior Contributor IV

Hi Pallav,

What device?

9s08gb60 etc

BR Peg

I guess its a QB8 as that is the included header file.

Have you tried erasing it then measure the pin? If its not 5V now (with the external pullup) then toss the chip and no need to look at the code!

Have you measured the pin with an oscilliscope? 2.9 volts on a multimeter could be a 60% duty cycle square wave.

PR Peg

 

Message Edited by peg on 04-22-200606:36 PM

0 件の賞賛
返信

1,428件の閲覧回数
pallavaggarwal
Contributor I

i am getting clean DC ont his pin (ptb7 and ptb6), i have noticed one fact while seeing via CRO that all the inputs are showing some wavy noise 300mv and when i pull up with 10k i get the 2.10v(same as getting with ptb6-7)

plz help is there any thing to stop other modules so as to fuction pin as Input/output pin only.

 

best regards

pallav

0 件の賞賛
返信

1,428件の閲覧回数
peg
Senior Contributor IV

Hi Pallav,

Like I already suggested... have you erased the device then checked it. When its erased all the i/o will be inputs with nothing to *accidently* make them otherwise.

BR Peg

0 件の賞賛
返信

1,428件の閲覧回数
pallavaggarwal
Contributor I
Thanks for ur reply again
u mean? i shuld check inserting an erased chip ,if pulling up with 10k on ptb7,6 and whether getting same condition or not....if this u mean..
 
i have check inserting the erased chip i have the following observations
when i pull up ptb6,7 it shows 2.10 volts dc (no pulses) but when i checked pullup on other ptb pins and pta port i got 5 volts.
 
 
best regards
Pallav  
0 件の賞賛
返信

1,428件の閲覧回数
peg
Senior Contributor IV

Yes that is what I mean.

Are you using DIP in a socket?

And I suppose you have tested with no device in the socket and you get 5V???

Very strange!!!

And you have tried several chips???

I don't have a QB only a QY4 and in my current application I use PTB0 to 6 as mode select inputs for testing and they all work OK although I have never measured the actual voltage.

What does the CPU read the 2.1 volts as, 0 or 1?

BR Peg

 

0 件の賞賛
返信

1,428件の閲覧回数
pallavaggarwal
Contributor I
 
it is a dip packeage and i m using with socket , i hav tried several chips too, in this case (2.1v is reading as zero)
 
best regards
Pallav
 
0 件の賞賛
返信

1,428件の閲覧回数
peg
Senior Contributor IV

Hi Pallav,

You did not confirm that you have measured the empty socket pin to see if its 5V without the device fitted!

I tested some input voltages on port pins of a QY4 with just the internal pullups.

Vcc = 4.97 ptb5 = 4.93 and pta5 = 4.95.

Which is about what I would expect.

What I would try next is to use a 4k7 resistor to temporarily pullup then down this pin and measure the voltage on the pin at all 3 conditions (off, up, down).

If you do not get much variation use a 1k.

(BTW you can use this test to determine the exact value of the internal pullup)

This will tell you how _hard_ this pin is set to 2.1V. Is it just biased there or what?

Not sure where to go from there but we won't know till you try.

BR Peg

 

0 件の賞賛
返信

1,428件の閲覧回数
pallavaggarwal
Contributor I
ohh finaly got the problem actually i have connected resistance and led on  this pin when i was learning use of ptb as output and by mistake the two ptb6,7 r still connected while i m using these two pins as input so confliction with the pull ups ..............my mistake,.... i dont know what made me not away from it to find it .....
any ways ...thank a lot peg ..for ur kind help
 
Best regards
 
0 件の賞賛
返信

1,428件の閲覧回数
peg
Senior Contributor IV
Hi Pallav,
If I understand you correctly, you have PTB7 configured as an input with no internal pullup with a 10k external pullup but it is only sitting at 2.9 volts instead of being very close to 5V. Is this correct.
 
The main reason I am thinking of is that you have one of the other functions of this pin enabled. What device is it on?
 
BR Peg
 
0 件の賞賛
返信