CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I need your opinion in my program that i just wrote. thx u.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mourad



Joined: 02 Apr 2014
Posts: 7

View user's profile Send private message

I need your opinion in my program that i just wrote. thx u.
PostPosted: Mon Apr 07, 2014 2:09 pm     Reply with quote

Code:

//RJ45 cable tester
#include "demo.h"
//////////////////////////////////////////////////////////////////////////////
#byte PORTA =  0x05
#byte PORTB =  0x06
#byte PORTC =  0x07
#byte PORTD =  0x08
//////////////////////////////////////////////////////////////////////////////
int1 TestSTPair(int8 p)             // Test traight-through pair p
{
   int address;
   address = p<<1;
// First half
   bit_set(PORTD,address);          // test High
   if (!bit_test(PORTC,address))
      return 0;
   bit_clear(PORTD,address);        // test Low
   if (bit_test(PORTC,address))
      return 0;
// Second half
   bit_set(PORTD,address+1);        // test High
   if (!bit_test(PORTC,address+1))
      return 0;
   bit_clear(PORTD,address+1);      // test Low
   if (bit_test(PORTC,address+1))
      return 0;
   return 1;
}
//////////////////////////////////////////////////////////////////////////////
void TestSTCable()               // Test traight-through cable
{
   int8 pair;
   PORTD = 0;
   PORTB = 0;
   for (pair = 0; pair < 4; pair++)       // scan pairs
   {
      if (TestSTPair(pair) && bit_test(PORTA,pair)) // selected & connected?
         bit_set(PORTB,pair+4);     // turn on LED
      delay_ms(500);       // wait a bit
      PORTB = 0;
   }
}
//////////////////////////////////////////////////////////////////////////////
int1 TestCOPair(int8 p)          // Test crossover pair p
{
   switch (p)
   {
      case 0:  bit_set(PORTD,0);          // test High
               if (!bit_test(PORTC,4))
                  return 0;
               bit_clear(PORTD,0);        // test Low
               if (bit_test(PORTC,4))
                  return 0;
               bit_set(PORTD,2);        // test High
               if (!bit_test(PORTC,5))
                  return 0;
               bit_clear(PORTD,2);      // test Low
               if (bit_test(PORTC,5))
                  return 0;
               break;
      case 1:  bit_set(PORTD,4);          // test High
               if (!bit_test(PORTC,0))
                  return 0;
               bit_clear(PORTD,4);        // test Low
               if (bit_test(PORTC,0))
                  return 0;
               bit_set(PORTD,5);        // test High
               if (!bit_test(PORTC,2))
                  return 0;
               bit_clear(PORTD,5);      // test Low
               if (bit_test(PORTC,2))
                  return 0;
               break;
      case 2:  bit_set(PORTD,6);          // test High
               if (!bit_test(PORTC,3))
                  return 0;
               bit_clear(PORTD,6);        // test Low
               if (bit_test(PORTC,3))
                  return 0;
               bit_set(PORTD,7);        // test High
               if (!bit_test(PORTC,1))
                  return 0;
               bit_clear(PORTD,7);      // test Low
               if (bit_test(PORTC,1))
                  return 0;
               break;
      case 3:  bit_set(PORTD,3);          // test High
               if (!bit_test(PORTC,6))
                  return 0;
               bit_clear(PORTD,3);        // test Low
               if (bit_test(PORTC,6))
                  return 0;
               bit_set(PORTD,1);        // test High
               if (!bit_test(PORTC,7))
                  return 0;
               bit_clear(PORTD,1);      // test Low
               if (bit_test(PORTC,7))
                  return 0;
               break;
   }
   return 1;
}
//////////////////////////////////////////////////////////////////////////////
void TestCOCable()      //Test crossover cable
{
   int8 pair;
   PORTD = 0;
   PORTB = 0;
   for (pair = 0; pair < 4; pair++)    // scan pairs
   {
      if (TestCOPair(pair) && bit_test(PORTA,pair)) // selected & connected?
         bit_set(PORTB,pair+4);     // turn on LED
      delay_ms(500);    // wait a bit
      PORTB = 0;
   }
}
//////////////////////////////////////////////////////////////////////////////
#int_EXT
void EXT_isr()    // External interrupt service routine
{
   if (bit_test(PORTB,1))
      TestSTCable(); // go and test straight-through cable
   else
      TestCOCable(); // go and test crossover cable
}
//////////////////////////////////////////////////////////////////////////////
void main()
{
   int8 counter;
   ///////////////////////// S E T U P ///////////////////////////
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   PORTA = 0;
   PORTB = 0;
   PORTC = 0;
   PORTD = 0;
   set_tris_a(0xFF);
   set_tris_b(0x0F);
   set_tris_d(0x00);
   set_tris_c(0xFF);
   ext_int_edge( H_TO_L );
   enable_interrupts(INT_EXT);
   enable_interrupts(global);

   // blink all LEDs ///////////////////////////
   for (counter=0;counter<4;counter++)
   {
      bit_set(PORTB,counter+4);
      delay_ms(100);
      PORTB=0;
   }
   /////////////////////////////////////////////
   while(1)
   {
      Sleep();             // Go to sleep
      delay_cycles(1);     // NOP
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 07, 2014 2:21 pm     Reply with quote

Those routines came from here:
http://borsfeco.no-ip.biz/Datasheets/Books/UTP%20cables.pdf
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

Re: I need your opinion in my program that i just wrote. thx
PostPosted: Sun Aug 17, 2014 10:23 am     Reply with quote

Could you demonstrate how you'd take the results and display them on an LCD instead of just LED's?

The LED output looks so mid 2006ish...

Or perhaps how to code the S1 switch bank to use keypad input variables instead to free up those pins.




mourad wrote:
Code:

//RJ45 cable tester
#include "demo.h"
//////////////////////////////////////////////////////////////////////////////
#byte PORTA =  0x05
#byte PORTB =  0x06
#byte PORTC =  0x07
#byte PORTD =  0x08
//////////////////////////////////////////////////////////////////////////////
int1 TestSTPair(int8 p)             // Test traight-through pair p
{
   int address;
   address = p<<1;
// First half
   bit_set(PORTD,address);          // test High
   if (!bit_test(PORTC,address))
      return 0;
   bit_clear(PORTD,address);        // test Low
   if (bit_test(PORTC,address))
      return 0;
// Second half
   bit_set(PORTD,address+1);        // test High
   if (!bit_test(PORTC,address+1))
      return 0;
   bit_clear(PORTD,address+1);      // test Low
   if (bit_test(PORTC,address+1))
      return 0;
   return 1;
}
//////////////////////////////////////////////////////////////////////////////
void TestSTCable()               // Test traight-through cable
{
   int8 pair;
   PORTD = 0;
   PORTB = 0;
   for (pair = 0; pair < 4; pair++)       // scan pairs
   {
      if (TestSTPair(pair) && bit_test(PORTA,pair)) // selected & connected?
         bit_set(PORTB,pair+4);     // turn on LED
      delay_ms(500);       // wait a bit
      PORTB = 0;
   }
}
//////////////////////////////////////////////////////////////////////////////
int1 TestCOPair(int8 p)          // Test crossover pair p
{
   switch (p)
   {
      case 0:  bit_set(PORTD,0);          // test High
               if (!bit_test(PORTC,4))
                  return 0;
               bit_clear(PORTD,0);        // test Low
               if (bit_test(PORTC,4))
                  return 0;
               bit_set(PORTD,2);        // test High
               if (!bit_test(PORTC,5))
                  return 0;
               bit_clear(PORTD,2);      // test Low
               if (bit_test(PORTC,5))
                  return 0;
               break;
      case 1:  bit_set(PORTD,4);          // test High
               if (!bit_test(PORTC,0))
                  return 0;
               bit_clear(PORTD,4);        // test Low
               if (bit_test(PORTC,0))
                  return 0;
               bit_set(PORTD,5);        // test High
               if (!bit_test(PORTC,2))
                  return 0;
               bit_clear(PORTD,5);      // test Low
               if (bit_test(PORTC,2))
                  return 0;
               break;
      case 2:  bit_set(PORTD,6);          // test High
               if (!bit_test(PORTC,3))
                  return 0;
               bit_clear(PORTD,6);        // test Low
               if (bit_test(PORTC,3))
                  return 0;
               bit_set(PORTD,7);        // test High
               if (!bit_test(PORTC,1))
                  return 0;
               bit_clear(PORTD,7);      // test Low
               if (bit_test(PORTC,1))
                  return 0;
               break;
      case 3:  bit_set(PORTD,3);          // test High
               if (!bit_test(PORTC,6))
                  return 0;
               bit_clear(PORTD,3);        // test Low
               if (bit_test(PORTC,6))
                  return 0;
               bit_set(PORTD,1);        // test High
               if (!bit_test(PORTC,7))
                  return 0;
               bit_clear(PORTD,1);      // test Low
               if (bit_test(PORTC,7))
                  return 0;
               break;
   }
   return 1;
}
//////////////////////////////////////////////////////////////////////////////
void TestCOCable()      //Test crossover cable
{
   int8 pair;
   PORTD = 0;
   PORTB = 0;
   for (pair = 0; pair < 4; pair++)    // scan pairs
   {
      if (TestCOPair(pair) && bit_test(PORTA,pair)) // selected & connected?
         bit_set(PORTB,pair+4);     // turn on LED
      delay_ms(500);    // wait a bit
      PORTB = 0;
   }
}
//////////////////////////////////////////////////////////////////////////////
#int_EXT
void EXT_isr()    // External interrupt service routine
{
   if (bit_test(PORTB,1))
      TestSTCable(); // go and test straight-through cable
   else
      TestCOCable(); // go and test crossover cable
}
//////////////////////////////////////////////////////////////////////////////
void main()
{
   int8 counter;
   ///////////////////////// S E T U P ///////////////////////////
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   PORTA = 0;
   PORTB = 0;
   PORTC = 0;
   PORTD = 0;
   set_tris_a(0xFF);
   set_tris_b(0x0F);
   set_tris_d(0x00);
   set_tris_c(0xFF);
   ext_int_edge( H_TO_L );
   enable_interrupts(INT_EXT);
   enable_interrupts(global);

   // blink all LEDs ///////////////////////////
   for (counter=0;counter<4;counter++)
   {
      bit_set(PORTB,counter+4);
      delay_ms(100);
      PORTB=0;
   }
   /////////////////////////////////////////////
   while(1)
   {
      Sleep();             // Go to sleep
      delay_cycles(1);     // NOP
   }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group