Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- MSP430G2553 Project Creator
- GE 423 - Dan Block
- Spring(2012)
- Written(by) : Steve(Keres)
- College of Engineering Control Systems Lab
- University of Illinois at Urbana-Champaign
- *******************************************************************************/
- #include "msp430g2553.h"
- #include "UART.h"
- char newprint = 0;
- unsigned long timecnt = 0;
- int pin27count = 0;
- int pin26count = 0;
- char debounce27 = 0;
- char debounce26 = 0;
- void main(void) {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- if (CALBC1_16MHZ ==0xFF || CALDCO_16MHZ == 0xFF) while(1);
- DCOCTL = CALDCO_16MHZ; // Set uC to run at approximately 16 Mhz
- BCSCTL1 = CALBC1_16MHZ;
- // initialize LEDs
- P1SEL &= 0x0F; // choosing I/O
- P1SEL2 &= 0x0F;
- P1DIR |= 0xF0; // choosing OUTPUT
- P1OUT = 0x10;
- P2SEL &= ~0x03;
- P2SEL2 &= ~0x03;
- P2DIR |= 0x03;
- // initialize switches
- P2SEL &= 0x3F; // choosing I/O
- P2SEL2 &= 0x3F;
- P2DIR &= 0x3F; // choosing INPUT
- P2REN |= 0xC0; // enabling pullups
- P2IE |= 0xC0; // enable interrupts
- P2IES |= 0xC0; // hi to low trigger
- P2IFG &= ~0xC0; // clear int flag
- // Timer A Config
- TACCTL0 = CCIE; // Enable Periodic interrupt
- TACCR0 = 16000; // period = 1ms
- TACTL = TASSEL_2 + MC_1; // source SMCLK, up mode
- Init_UART(9600,1); // Initialize UART for 9600 baud serial communication
- _BIS_SR(GIE); // Enable global interrupt
- UART_printf("Reboot\r\n");
- while(1)
- {
- if (newprint)
- {
- UART_printf("Sw1 Cnt: %d, Sw2 Cnt: %d\n\r",(int)pin26count, (int)pin27count);
- newprint = 0;
- }
- }
- }
- // Timer A0 interrupt service routine
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void Timer_A (void)
- {
- timecnt++; // Keep track of time for main while loop.
- if ((timecnt%500) == 0) {
- newprint = 1; // flag main while loop that .25 seconds have gone by.
- }
- if (debounce27)
- {
- debounce27++;
- if (debounce27 >= 10) // wait 10ms
- {
- P2IE |= 0x80; // renable interrupt
- debounce27 = 0; // clear flag
- }
- }
- if (debounce26)
- {
- debounce26++;
- if (debounce26 >= 10) // wait 10ms
- {
- P2IE |= 0x40; // renable interrupt
- debounce26 = 0; // clear flag
- }
- }
- }
- #pragma vector=PORT2_VECTOR
- __interrupt void Port_2(void)
- {
- if (P2IFG & 0x80) // P2.7
- {
- pin27count++; // increment count
- P2IFG &= ~0x80; // clear INT flag
- P2OUT ^= 0x02; // toggle p2.1
- debounce27 = 1; // set debounce flag
- P2IE &= ~0x80; // INT disable
- }
- if (P2IFG & 0x40) // P2.6
- {
- pin26count++; // increment count
- P2IFG &= ~0x40; // clear INT flag
- P2OUT ^= 0x01; // toggle p2.0
- debounce26 = 1; // set debounce flag
- P2IE &= ~0x40; // INT disable
- }
- }
- /*
- // ADC 10 ISR - Called when a sequence of conversions (A7-A0) have completed
- #pragma vector=ADC10_VECTOR
- __interrupt void ADC10_ISR(void) {
- }
- */
- // USCI Transmit ISR - Called when TXBUF is empty (ready to accept another character)
- #pragma vector=USCIAB0TX_VECTOR
- __interrupt void USCI0TX_ISR(void) {
- if(IFG2&UCA0TXIFG) { // USCI_A0 requested TX interrupt
- if(printf_flag) {
- if (currentindex == txcount) {
- senddone = 1;
- printf_flag = 0;
- IFG2 &= ~UCA0TXIFG;
- } else {
- UCA0TXBUF = printbuff[currentindex];
- currentindex++;
- }
- } else if(UART_flag) {
- if(!donesending) {
- UCA0TXBUF = txbuff[txindex];
- if(txbuff[txindex] == 255) {
- donesending = 1;
- txindex = 0;
- }
- else txindex++;
- }
- } else { // interrupt after sendchar call so just set senddone flag since only one char is sent
- senddone = 1;
- }
- IFG2 &= ~UCA0TXIFG;
- }
- if(IFG2&UCB0TXIFG) { // USCI_B0 requested TX interrupt (UCB0TXBUF is empty)
- IFG2 &= ~UCB0TXIFG; // clear IFG
- }
- }
- // USCI Receive ISR - Called when shift register has been transferred to RXBUF
- // Indicates completion of TX/RX operation
- #pragma vector=USCIAB0RX_VECTOR
- __interrupt void USCI0RX_ISR(void) {
- if(IFG2&UCB0RXIFG) { // USCI_B0 requested RX interrupt (UCB0RXBUF is full)
- IFG2 &= ~UCB0RXIFG; // clear IFG
- }
- if(IFG2&UCA0RXIFG) { // USCI_A0 requested RX interrupt (UCA0RXBUF is full)
- // Uncomment this block of code if you would like to use this COM protocol that uses 253 as STARTCHAR and 255 as STOPCHAR
- /* if(!started) { // Haven't started a message yet
- if(UCA0RXBUF == 253) {
- started = 1;
- newmsg = 0;
- }
- }
- else { // In process of receiving a message
- if((UCA0RXBUF != 255) && (msgindex < (MAX_NUM_FLOATS*5))) {
- rxbuff[msgindex] = UCA0RXBUF;
- msgindex++;
- } else { // Stop char received or too much data received
- if(UCA0RXBUF == 255) { // Message completed
- newmsg = 1;
- rxbuff[msgindex] = 255; // "Null"-terminate the array
- }
- started = 0;
- msgindex = 0;
- }
- }
- */
- IFG2 &= ~UCA0RXIFG;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement