Author Topic: How to use the led's on the pt32e  (Read 2944 times)

coosadog

  • Newbie
  • *
  • Posts: 1
    • View Profile
How to use the led's on the pt32e
« on: October 14, 2009, 08:02:16 AM »
I purchased the above, along with a few other things from you Modtronix.  I can't locate any examples of how to turn on the led's on the pt32e.  All I found was the following brief comment on the data sheet:

- Configure C0 as an output (trisc bit 0 = 0)
- Clock out all data for the serial/parallel shift registers on C0
- Output a pulse (high-low-high) onto C2.  This will do two things:
1) Latch serial data out of serial/parallel shift registers (on rising edge of clock)
2) Latch parallel data into parallel/serial shift registers (on low level)
- Configure C0 as an input (so we can read parallel/serial shift registers)
- Clock in all data latched (on low C2) into parallel/serial shift registers

That's not much but I took that and did some research on the chip that's on the pt32e (74hc595) and came up with the following:

C0 = serial data input
C1 = shift register clock input
C2 = storage register clock input

So I coded up the following C function using sourceboost C:

void OutLED(unsigned char data)
{
   unsigned char bits;
   
   clear_bit(trisc,0);                      // make port C0 pin output
   for (bits=0x80; bits!=0; bits >>= 1)
   {
      if ((bits & data) == bits)            // if bit is set
         set_bit(portc,0);                  // bit was on, set c0 to 1
      else
         clear_bit(portc,0);                // bit was off, set c0 to 0
     
      set_bit(portc,1);                     // clock the
      clear_bit(portc,1);                   //           data
   }
   set_bit(portc,2);                        // Latch 
   clear_bit(portc,2);                      //       the 
   set_bit(portc,2);                        //            data 
}


Which doesn't work!  What am I doing wrong, or rather, how do I do this?  Everything else is working fine but I'd like to use the led's.  Surely there is a test program laying around for this.

Alain

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: How to use the led's on the pt32e
« Reply #1 on: October 15, 2009, 05:21:53 AM »
Try with my code it works fine for me. If you change or add something please let me know.

Alain