Skip to content

Instantly share code, notes, and snippets.

@squaredisk
Created August 19, 2010 21:51
Show Gist options
  • Save squaredisk/539023 to your computer and use it in GitHub Desktop.
Save squaredisk/539023 to your computer and use it in GitHub Desktop.
CatsEyes - Cat5/6 network cable tester
///////////////////////////////////////////////////////////////////////////////
//
// CatsEyes - 29/08/2010
// Cat5/6 network cable tester with 3 operating modes: Slow, fast and manual
//
// LEDs connected on P1.0 - P1.7 (red) and P2.7 (green)
// Momentary switches on RST and P2.6
//
// Gareth Williams // SquareDisk // All round, different
//
#include "msp430g2211.h"
void next_led(void);
volatile int ticks = 0; // counts the WDT interrupts
volatile char mode = 0; // 0 = slow, 1 = fast, 2 = manual
volatile int debounce = 2000; // disables the buttons until WDT decreases this to 0
int main (void)
{
WDTCTL = WDTPW + WDTHOLD; // stop the watchdog timer
// set up the clocks for the factory preset 1MHz
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
// enable P1.0 to P1.7 as outputs
P1DIR = BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P1OUT = BIT0; // flip LED1 on, all others off
P1SEL = 0;
P2DIR = BIT7; // enable P2.7 as an output
P2OUT &= ~BIT7; // make sure P2.7 is off
P2SEL &= ~BIT7;
// set up the interrupt for the button
P2IE |= BIT6;
P2IES |= BIT6;
P2IFG &= ~BIT6; // clear the interrupt flag
// Enable NMI function of the RST pin
// WDTTMSEL = Interval timer mode
// clock source is SMCLK (1MHz or 1000000Hz)
// Interval is clock /64 (15625 interrupts per second)
WDTCTL = WDTPW + WDTNMI + WDTTMSEL + WDTCNTCL + WDTIS1 + WDTIS0;
IE1 |= WDTIE + NMIIE; // enable WDT and NMI interrupts
_bis_SR_register(LPM1_bits + GIE); // enter low power mode w/ interrupts
}
void next_led(void)
{
switch (P1OUT)
{
case 0: // start from the LED1
P1OUT = BIT0;
P2OUT = 0;
break;
case BIT7: // turn on LED9, the green/shield test
P1OUT = 0;
P2OUT = BIT7;
break;
default: // shift the bit left one digit to light the next red LED
P1OUT = P1OUT << 1;
}
}
#pragma vector=WDT_VECTOR
__interrupt void wdt_trigger(void)
{
// WDT is triggered 15625 times per second
ticks++;
if (debounce > 0)
{
debounce--;
}
switch (mode)
{
case 0:
if (ticks == 15635)
{
next_led();
ticks = 0;
}
break;
case 1:
if (ticks == 5000)
{
next_led();
ticks = 0;
}
break;
}
}
#pragma vector=NMI_VECTOR
__interrupt void nmi_trigger(void)
{
// WDTCTL = WDTPW + WDTNMI;
if (debounce == 0)
{
mode = ++mode % 3; // cycle the mode counter
ticks = 0;
debounce = 2000;
}
IFG1 &= ~NMIIFG; // clear the NMI interrupt flag
IE1 |= NMIIE;
}
#pragma vector=PORT2_VECTOR
__interrupt void button_trigger(void)
{
next_led();
P2IFG &= ~BIT6; // clear the interrupt flag
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment