Ping Ultra Sonic sensor with MC9S12DG256

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ping Ultra Sonic sensor with MC9S12DG256

1,461 Views
JoeD_
Contributor I
I'm using the iccv7 compiler for the MC9S12DG256 and I'm trying to help my buddy by programming it to use the Ping Ultra Sonic Sensor from Parallax. I've successfully coded it for a basic Stamp, but now when I'm trying to code it in C in iccv7 I'm having problems with the PORT T timer. I'm at work right now so I'm not able to paste up the code, I will do that once home, but I was just wondering if anyone has ever used this sensor before any may have examples. Thanks for any help!


Joe
Labels (1)
0 Kudos
1 Reply

378 Views
JoeD_
Contributor I
so i gave up an the timer control and now  i'm trying to manually do it. Heres my code


DDRH = 0x80;      // PH7 out
PPSH = 0x80;      // pull-DOWN PH7
PERH = 0x80;      // enable them

PTH = 0x80;
delay10u();
PTH = 0x00; 

DDRH = 0x7F;      // PH7 in 
PPSH = 0x80;      // pull-DOWN PH7
PERH = 0x80;      // enable them
PTH =  0x00;
  
  while(1)
    {  
       
         if (PTH &0x80)
        { 
            while(PTH &0x80){i ++;} //Sit and wait for falling edge
             printf("%d\n\r" ,i );
            i = 0;
        }
    
     }

All I'm trying to do here is pulse a 1 out for 10us which enable the SRF05, then switch port h pin 7 back to input and wait for to go back high then increment i while high, and based of the count of i, i can determine the distance.

SRF05 datasheet



0 Kudos