Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <msp430FG4618.h>
- #include <stdio.h>
- #include <math.h>
- #define a 0x08 // LCD индикатора
- #define b 0x04
- #define c 0x02
- #define d 0x01
- #define e 0x20
- #define f 0x10
- #define g 0x40
- #define h 0x80
- #define minus 0x40
- #define LCD_MEM_OFFSET 2 // Offset from LCDMEM[0]
- #define LCD_MEM_LOC 11 // Num of LCDMEM[] locations used
- volatile unsigned int count = 0; // impulse counter
- volatile float vel1 = 0; // first velocity
- volatile float vel2 = 0; // second velocity
- volatile float accel = 0; // acceleration
- unsigned char digits[10] = { // 0 - 9 numbers
- a+b+c+d+f+g,
- b+c,
- a+d+c+e+g,
- a+b+c+d+e,
- b+c+e+f,
- d+f+e+b+a,
- d+f+g+a+b+e,
- f+d+c+b,
- a+b+c+d+f+e+g,
- a+b+c+d+f+e
- };
- void lcd_init() {
- LCDACTL = LCDON + LCD4MUX + LCDFREQ_128; // turn LCD on
- LCDAPCTL0 = LCDS4 + LCDS8 + LCDS12 + LCDS16 + LCDS20 + LCDS24;
- P5SEL |= BIT2 + BIT3 + BIT4; // COM1 + COM2 + COM3
- LCDMEM[3] = 0;
- LCDMEM[4] = 0;
- LCDMEM[5] = 0;
- LCDMEM[6] = 0;
- LCDMEM[7] = 0;
- LCDMEM[8] = 0;
- LCDMEM[9] = 0;
- }
- void lcd_clear() {
- for (int i = LCD_MEM_OFFSET; i < (LCD_MEM_OFFSET + LCD_MEM_LOC); i++) {
- LCDMEM[i] = 0;
- }
- }
- void input_init() {
- P1DIR &= ~0x05; // P1.0 - CCI0A, P1.2 - CCI1A
- P1SEL |= 0x05;
- }
- void timerA0_init() {
- TACCR0 = 31250 - 1; // SMCLK - 1 MHz, divided by 8 it is 125000, 31250 is 1/4 of SMCLK divided by 8
- TACCTL0 |= CCIE; // CCR0 interrupt enabled
- TACCTL1 |= CM_1 + CCIS_0 + CAP + CCIE; // capture front rising + CCI1A + capture mode + CCR1 interrupt enabled
- TACTL = TASSEL_2 + ID_3 + MC_1 + TACLR; // SMCLK + divider /8 + continuous mode + TAIE
- }
- void calculations() {
- vel1 = vel2; // 32 max counts per sec, 8 counts per 1/4 sec
- vel2 = count * 4 * M_PI; // vel = (count * M_PI) / (1/4)
- accel = abs((vel2 - vel1)) * 4; // accel = abs((vel2 - vel1)) / (1/4)
- count = 0; // reset counter
- }
- void lcd_print() {
- int k = (int)acceleration % 10;
- LCDMEM[2] = digits[(k & 0x0F)];
- int n = (int)acceleration / 10;
- k = n % 10;
- LCDMEM[3] = digits[(k & 0x0F)];
- n = n / 10;
- k = n % 10;
- LCDMEM[4] = digits[(k & 0x0F)];
- n = n / 10;
- k = n % 10;
- LCDMEM[5] = digits[(k & 0x0F)];
- n = n / 10;
- }
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
- lcd_init();
- lcd_clear();
- input_init();
- timerA0_init();
- __enable_interrupt(); // Enable interrupts
- }
- #pragma vector=TIMERA0_VECTOR
- __interrupt void timer_accel_calculation(void) {
- calculations();
- printf("acceleration %.2f \n", accel);
- lcd_print();
- }
- #pragma vector=TIMERA1_VECTOR
- __interrupt void timer_input_capture(void) {
- switch(__even_in_range(TAIV,10))
- {
- case 2 : // TACCR1 CCIFG
- count++; // counting input pulses
- break;
- default:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement