Ejemplo n.º 1
0
int main()
{
	WDTCTL = WDTPW | WDTHOLD;

	DCOCTL = CALDCO_16MHZ;
	BCSCTL1 = CALBC1_16MHZ;
	BCSCTL2 = DIVS_1;  // SMCLK = DCO/2 (8MHz)

	//__delay_cycles(8000);  // Short delay to let the LCD wake up -- turns out this isn't necessary
	// Chip select
	P2DIR |= BIT0;
	P2OUT |= BIT0;  // Drive it high to disable LCD
	// Backlight
	P2DIR |= BIT5;
	P2OUT |= BIT5; // Turn on backlight

	spi_init();
	msp1202_init();
	lcd_printf("Hi there my\n");
	lcd_printf("name is Eric.\n");
	msp1202_move(8, 0);

	while(1) {
		__delay_cycles(16000000);
		lcd_printf("txt %d", 1);
		__delay_cycles(16000000);
		lcd_printf("txt %d", 2);
	}

	LPM4;

	return 0;
}
Ejemplo n.º 2
0
int main()
{
	WDTCTL = WDTPW | WDTHOLD;

	//__delay_cycles(8000);  // Short delay to let the LCD wake up -- turns out this isn't necessary
	// Chip select
	P1DIR |= BIT5;
	P1OUT |= BIT5;  // Drive it high to disable LCD
	// Backlight
	P1SEL0 &= ~BIT2;
	P1SEL1 &= ~BIT2;
	P1DIR |= BIT2;
	P1OUT |= BIT2; // Turn on backlight
	// LFXT1 pins
	PJSEL0 = BIT4 | BIT5;
	PJSEL1 = 0x00;

	PM5CTL0 &= ~LOCKLPM5;  // Enable GPIO on Wolverine
	// Wolverine Clock System setup
	CSCTL0_H = CSKEY >> 8;
	FRCTL0 = FWPW | NACCESS_2;  // 24MHz (2 wait states)
	CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
	CSCTL3 = DIVA__1 | DIVS__4 | DIVM__1;
	CSCTL1 = DCORSEL | DCOFSEL_6;  // 24MHz
	CSCTL4 &= ~LFXTOFF;
	do {
		CSCTL5 &= ~LFXTOFFG;
		SFRIFG1 &= ~OFIFG;
	} while (SFRIFG1 & OFIFG);
	CSCTL0_H = 0;

	spi_init();
	msp1202_init();
	lcd_printf("Hi there my\n");
	lcd_printf("name is Eric.\n");
	msp1202_move(8, 0);

	while(1) {
		__delay_cycles(16000000);
		lcd_printf("txt %d", 1);
		__delay_cycles(16000000);
		lcd_printf("txt %d", 2);
	}

	LPM4;

	return 0;
}
Ejemplo n.º 3
0
int main()
{
	WDTCTL = WDTPW | WDTHOLD;

	DCOCTL = CALDCO_16MHZ;
	BCSCTL1 = CALBC1_16MHZ;
	BCSCTL2 = DIVS_1;  // SMCLK = DCO/2 (8MHz)

	//__delay_cycles(8000);  // Short delay to let the LCD wake up -- turns out this isn't necessary
	// Chip select
	P2DIR |= BIT0;
	P2OUT |= BIT0;  // Drive it high to disable LCD
	// Backlight
	P2DIR |= BIT5;
	P2OUT |= BIT5; // Turn on backlight
	// Pushbuttons
	P2DIR &= ~(BIT3 | BIT4);
	P2OUT |= BIT3 | BIT4;
	P2REN |= BIT3 | BIT4;
	P2IES |= BIT3 | BIT4;
	P2IFG &= ~(BIT3 | BIT4);
	P2IE |= BIT3 | BIT4;

	spi_init();
	msp1202_init();
	ste2007_contrast(8);
	lcd_printf("Hi there my\n");
	lcd_printf("name is Eric.\n");
	_EINT();

	while(1) {
		if ( (~P2IN) & (BIT3|BIT4) ) {
			if (!(P2IN & BIT3)) {
				lcd_printf("S1 pressed\n");
				P2OUT ^= BIT5;
			}
			if (!(P2IN & BIT4)) {
				lcd_printf("S2 pressed\n");
			}
		}
		LPM4;
	}

	return 0;
}
Ejemplo n.º 4
0
int main()
{
	WDTCTL = WDTPW | WDTHOLD;

	DCOCTL = CALDCO_16MHZ;
	BCSCTL1 = CALBC1_16MHZ;
	BCSCTL2 = DIVS_3;  // SMCLK = DCO/8 (2MHz)

	//__delay_cycles(8000);  // Short delay to let the LCD wake up -- turns out this isn't necessary
	// Chip select
	P2SEL &= ~BIT4;
	P2SEL2 &= ~BIT4;
	P2REN &= ~BIT4;
	P2DIR |= BIT4;
	P2OUT |= BIT4;  // Drive it high to disable LCD
	// Backlight
	P3SEL &= ~BIT6;
	P3SEL2 &= ~BIT6;
	P3REN &= ~BIT6;
	P3DIR |= BIT6;
	P3OUT |= BIT6; // Turn on backlight

	spi_init();
	// 250ms delay to let the Nokia display wake up out of RESET
	__delay_cycles(16000000 / 4);

	msp1202_init();
	ste2007_contrast(8);
	msp1202_puts("Hi there my\n");
	msp1202_puts("name is Eric.\n");
	msp1202_move(8, 0);

	while(1) {
		__delay_cycles(16000000);
		msp1202_puts("txt 1");
		__delay_cycles(16000000);
		msp1202_puts("txt 2");
	}

	LPM4;

	return 0;
}
Ejemplo n.º 5
0
int main()
{
	WDTCTL = WDTPW | WDTHOLD;

	P4DIR |= BIT7;
	P4OUT |= BIT7;
	if (!ucs_clockinit(16000000, 1, 0))
		LPM4;
	P4OUT &= ~BIT7;
	UCSCTL5 = DIVS__4;

	// Chip select
	P2SEL &= ~BIT7;
	P2REN &= ~BIT7;
	P2DIR |= BIT7;
	P2OUT |= BIT7;  // Drive it high to disable LCD
	// Backlight
	P2SEL &= ~BIT6;
	P2REN &= ~BIT6;
	P2DIR |= BIT6;
	P2OUT &= ~BIT6; // Turn off backlight

	spi_init();
	msp1202_init();
	ste2007_contrast(8);
	msp1202_puts("Hi there my\n");
	msp1202_puts("name is Eric.\n");
	msp1202_move(8, 0);

	while(1) {
		__delay_cycles(16000000);
		msp1202_puts("txt 1");
		__delay_cycles(16000000);
		msp1202_puts("txt 2");
	}

	LPM4;

	return 0;
}
Ejemplo n.º 6
0
int main()
{
	uint8_t do_lpm, is_ext;
	int i, j, k;
	uint32_t msgid;

	WDTCTL = WDTPW | WDTHOLD;
	DCOCTL = CALDCO_16MHZ;
	BCSCTL1 = CALBC1_16MHZ;
	BCSCTL2 = DIVS_1;
	BCSCTL3 = LFXT1S_2;
	while (BCSCTL3 & LFXT1OF)
		;
	
	P1SEL &= ~BIT0;
	P1SEL2 &= ~BIT0;
	P1DIR |= BIT0;
	P1OUT &= ~BIT0;
	sleep_counter = SLEEP_COUNTER;
	inbuf[8] = '\0';

	can_init();
	if (can_speed(500000, 1, 3) < 0) {
		P1OUT |= BIT0;
		LPM4;
	}

	// LCD init
	P2SEL &= ~(BIT0 | BIT5);
	P2SEL2 &= ~(BIT0 | BIT5);
	P2DIR |= BIT0 | BIT5;
	P2OUT |= BIT0 | BIT5;
	msp1202_init();
	msp1202_puts("CAN printer\n0x00000080-\n");

	can_rx_setmask(0, 0xFFFFFFFF, 1);
	can_rx_setmask(1, 0xFFFFFFFF, 1);
	can_rx_setfilter(0, 0, 0x00000080);
	can_rx_mode(0, MCP2515_RXB0CTRL_MODE_RECV_STD_OR_EXT);

	can_ioctl(MCP2515_OPTION_LOOPBACK, 0);
	can_ioctl(MCP2515_OPTION_ONESHOT, 0);
	can_ioctl(MCP2515_OPTION_ROLLOVER, 1);

	/* Flowchart for program flow:
	 *
	 *        START
	 *          |
	 *          +---------<-------------------+-----------<-----------------------+
	 *          |                             |                                   |
	 *         \|/                           /|\                                  |
	 *   --------------                       |                                   |
	 *  /               \         +------+    |                                   |
	 * < Is IRQ pending? > No->---| LPM4 |->--+                                   |
	 *  \               /         +------+                                       /|\
	 *    -------------                                                           |
	 *         Yes                                                                |
	 *          |                                                                 |
	 *         \_/                                                                |
	 *    -----------              -------------                                  |
	 *  /             \          /               \                                |
	 * < Is IRQ_ERROR? > Yes->--< Is IRQ_HANDLED? > Yes->-------------------------+
	 *  \             /          \               /                                |
	 *    -----------              -------------                                  |
	 *         No                        No                                       |
	 *         |                         |                                       /|\
	 *        \_/                       \_/                                       |
	 *     --------                   --------           +-----------------+      |
	 *   /          \               /          \         | Cancel TX using |      |
	 *  < Is IRQ_RX? > No->---->---< Is IRQ_TX? > Yes->--| can_tx_cancel() |->----+
	 *   \          /               \          /         +-----------------+      |
	 *     --------                   --------                                    |
	 *        Yes                        No                                       |
	 *         |                         |                                       /|\
	 *        \_/                       \_/                                       |
	 *  +----------------+      +-------------------+                             |
	 *  | Pull data      |      | Bus error, wait   |                             |
	 *  | using can_recv |      | 100ms and recheck |->---------------------------+
	 *  +----------------+      | IRQ.              |                             |
	 *          |               +-------------------+                             |
	 *         \_/                                                                |
	 *   +--------------+                                                        /|\
	 *   | Write buffer |                                                         |
	 *   | contents to  |                                                         |
	 *   | LCD using    |->--------------------------->---------------------------+
	 *   | msp1202_puts |
	 *   +--------------+
	 *
	 *
	 *
	 */
	while(1) {
		do_lpm = 1;
		if (mcp2515_irq) {
			irq = can_irq_handler();
			if (irq & MCP2515_IRQ_ERROR) {
				if ( !(irq & MCP2515_IRQ_HANDLED) ) {
					if (irq & MCP2515_IRQ_TX) {
						can_tx_cancel();
					} else {
						// Bus error; wait 100ms, recheck
						P1OUT |= BIT0;
						__delay_cycles(1600000);
						P1OUT &= ~BIT0;
						do_lpm = 0;
					}
				} else {
					// RX overflow, most likely
					msp1202_puts("RX OVERFLOW\n");
				}
			}
			if (irq & MCP2515_IRQ_RX) {
				j = 0;
				k = can_rx_pending();
				do {
					i = can_recv(&msgid, &is_ext, inbuf+j);
					if ( !(i & 0x40) ) {
						j += i;
					}
					//msp1202_putc(k + '0', 0); msp1202_putc(' ', 0);
				} while ( (k = can_rx_pending()) >= 0 );
				//inbuf[j++] = '\n'; inbuf[j] = '\0';
				inbuf[j] = '\0';
				msp1202_puts((char*)inbuf);
				//msp1202_putc('\n', 1);
			} else {
				if (irq & MCP2515_IRQ_TX) {
					can_tx_cancel();
				}
			}
		}

		if ( do_lpm && !(mcp2515_irq & MCP2515_IRQ_FLAGGED) ) {
			LPM4;
		}
	}
	return 0;
}