Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <in430.h>
- #include <intrinsics.h>
- #include <msp430f1611.h>
- #include <stdint.h>
- #define DEBOUNCE_VALUE 20 // approx 20ms
- #define BUT_A 0x04
- #define BUT_B 0x02
- #define TXD BIT2
- #define RXD BIT1
- #define PERIOD 64
- #define MIN_BRIGHTNESS 0
- #define MAX_BRIGHTNESS 7
- volatile uint8_t buttonStates = 0;
- volatile uint8_t buttonADebounce = 0;
- volatile uint8_t buttonBDebounce = 0;
- volatile uint8_t brightness = MIN_BRIGHTNESS;
- volatile uint8_t digit = 0;
- volatile uint8_t string[8] = {0,1,2,3,9,5,6,8};
- volatile uint8_t brightnessMap[MAX_BRIGHTNESS] = {PERIOD-1, PERIOD*4/5, PERIOD*3/5, PERIOD/2, PERIOD/4, PERIOD/8, PERIOD/16};
- volatile uint8_t shouldRefresh = 0;
- void init();
- void handleDisplay();
- int main(void) {
- WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
- BCSCTL2 = SELM_3 | SELS;
- init();
- P2OUT = 0xFE;
- while(1) { }
- }
- inline void init() {
- TBCCR0 = 80; // approx 100 us
- //TBCCTL0 = CCIE; // enable ints
- TBCTL = TBSSEL_1 + MC_1 + ID_0; //wybieramy ACLK (32768Hz), tryb UP
- TBR = 0; // clear counting reg
- TACCR0 = PERIOD; // 1kHz
- TACCR1 = brightnessMap[brightness];
- TACCTL0 = CCIE; // enable ints
- TACCTL1 = CCIE; // enable ints
- TACTL = TASSEL_1 + MC_1 + ID_0; //wybieramy ACLK (32768Hz), tryb UP
- TAR = 0; // clear counting reg
- P2DIR = 0xFF; // digit select
- P1DIR = 0xFF; // value
- P3SEL |= RXD | TXD; // P1.1 = RXD, P1.2=TXD
- P3DIR = 0x00;
- U0CTL |= SWRST;
- U0CTL |= CHAR; // 8-bit characterUTCTL0 |= SSEL1;
- ME1 |= UTXE0 | URXE0; // Enabled USART0 TXD RXD
- IE1 |= URXIE0 | UTXIE0; //Wlaczenie przerwan dla modulu pobierajacego dane
- // Ustawienia dla 115200
- U0BR0 = 0x40;
- U0BR1 = 0x00;
- U0MCTL = 0x4A;
- U0CTL &= ~SWRST; // Wylaczenie software reset
- _EINT();
- }
- const char stringtosent[] = { "Hello World\r\n" };
- unsigned int i; //Counter
- #pragma vector=USART0TX_VECTOR
- __interrupt void USCI0TX_ISR(void)
- {
- U0TXBUF = stringtosent[i++]; // TX next character
- if (i == sizeof stringtosent - 1) // TX over?
- IE1 &= ~UTXE0; // Disable USCI_A0 TX interrupt
- }
- #pragma vector=USART0RX_VECTOR
- __interrupt void USCI0RX_ISR(void)
- {
- if (U0RXBUF == 'a') // 'a' received?
- {
- i = 0;
- IE1 |= UTXE0; // Enable USCI_A0 TX interrupt
- U0TXBUF = stringtosent[i++];
- }
- }
- #pragma vector=TIMERA0_VECTOR
- __interrupt void Timer_A0 (void)
- {
- P2OUT = 0xFF;
- P1OUT = (string[7-digit] & 0x0F) | 0xF0;
- P2OUT = ~(1 << digit);
- digit = (digit+1) & 0x07;
- }
- #pragma vector=TIMERA1_VECTOR
- __interrupt void Timer_A1 (void)
- {
- switch(TAIV) {
- case 0x00:
- break;
- case 0x02:
- P2OUT = 0xFF;
- break;
- default:
- break;
- }
- }
- #pragma vector=TIMERB0_VECTOR
- __interrupt void Timer_B0 (void)
- {
- __bic_SR_register_on_exit(CPUOFF);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement