|
|
View previous topic :: View next topic |
Author |
Message |
mourad
Joined: 02 Apr 2014 Posts: 7
|
I need your opinion in my program that i just wrote. thx u. |
Posted: Mon Apr 07, 2014 2:09 pm |
|
|
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
|
|
|
Aurbo
Joined: 07 Apr 2008 Posts: 49
|
Re: I need your opinion in my program that i just wrote. thx |
Posted: Sun Aug 17, 2014 10:23 am |
|
|
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
}
} |
|
|
|
|
|
|
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
|