Cov txheej txheem:

MSP430 Seconds Counter: 10 Kauj Ruam
MSP430 Seconds Counter: 10 Kauj Ruam

Video: MSP430 Seconds Counter: 10 Kauj Ruam

Video: MSP430 Seconds Counter: 10 Kauj Ruam
Video: Traffic Light Circuit Using | 555 Timer IC | Led Projects. 2024, Kaum ib hlis
Anonim
MSP430 Seconds Counter
MSP430 Seconds Counter

Txais tos! Ua Tus Thib Ob Lub Sijhawm: Siv CCStudio 8 thiab MSP430F5529 rau txoj haujlwm.

C hom lus rau tus lej tswj hwm micro. Ua Ntawv Thov Lub Hwj Huam Tsawg, Timers thiab cuam tshuam. Qhov tso tawm tau tshwm ntawm 7 Segment.

Kauj Ruam 1: Kev nkag siab

Kev nkag siab
Kev nkag siab

Cia Peb Pib!

Pib lub sijhawm saib xyuas lub sijhawm rau OFF lub xeev siv tus lej xav tau rau lub sijhawm saib xyuas (Nws pab txhawm rau txheeb xyuas qhov tsis muaj qhov kawg, ua kom lub tshuab ua haujlwm nyab xeeb).

#suav nrog

/** * main.c */

int main (tsis muaj dab tsi)

{

WDTCTL = WDTPW | WDTHOLD; // nres lub moos timer

rov 0;

}

Kauj Ruam 2: Qhov Chaw Pib Pib

{

P3DIR = 0xFF; // P3DIR = 0x00;

P6DIR = 0xFF;

P4DIR | = 0x00;

P4REN | = 0xFF;

P4OUT | = 0xFF;

}

P3DIR | = 0x00 qhia peb tias tag nrho ntawm PORT-3 tau pib ua kom tau txais cov tswv yim.

P3DIR | = 0xFF qhia peb tias tag nrho ntawm PORT-3 tau pib ua ntej los muab cov txiaj ntsig.

P3DIR | = 0x01 tsuas yog tus pin P3.0 tau pib ua ntej rau hauv PORT-3. Qhov no ua raws Hexadecimal Port koog.

P4REN | = 0xFF, qhov no qhia tau hais tias cov pins ntawm PORT-4 muaj lawv rub tawm/nqis resistors qhib.

Txhawm rau xaiv lawv ntawm Rub UP lossis Rub DOWN, kev qhia P $ OUT | = 0xFF tau siv.

Yog tias 0xFF raug siv lawv teeb tsa raws li Rub UP resistors thiab yog 0x00 lawv teeb tsa raws li Rub DOWN.

Kauj Ruam 3: Ultra Low Power

MSP430F5529 tso cai rau peb kom txo hwj chim poob los ntawm tus txheej txheem. Qhov no muaj txiaj ntsig hauv daim ntawv thov ib leeg.

Qhov no hu rau tshaj tawm ntawm txhua tus pin lossis Ports rau cov zis.

{

P7DIR | = 0xFF;

P6DIR | = 0xFF;

P5DIR | = 0xFF;

P4DIR | = 0xFF;

P3DIR | = 0xFF;

P2DIR | = 0xFF;

P1DIR | = 0xFF;

}

Kauj ruam 4: TIMER

Kev siv timer rau ncua sijhawm ntawm ib thib ob. Qhov no siv SMCLK ntawm 1MHz, tseem siv sijhawm ua haujlwm nyob rau hauv Lub zog qis (nyob rau theem tom ntej, tom qab suav nws cuam tshuam los ntawm LPM). Cov txheej txheem no txuag lub zog thiab lub nra ntawm tus neeg ua haujlwm

TA0CCTL0 = CCIE;

TA0CCR0 = 999;

TA0CTL = TASSEL_2 + MC_1;

Qhov muaj txiaj ntsig yog 999, raws li siv ib qho ntxiv suav rov qab rau xoom hauv lub sijhawm teev npe.

Kauj Ruam 5: Hom Tsawg Zog

_BIS_SR (LPM0_bits+GIE);

Qhov no ua rau General cuam tshuam Enable (GIE), thiab tso CPU rau LPM0, qhov twg MCLK uas txhawb nqa cpu tawm, thiab SMCLK thiab ACLK khiav uas ua kom lub sijhawm ua haujlwm. yog li peb tuaj yeem pom CPU raug kaw, nyob ntawd los ntawm kev txuag lub zog.

Kauj Ruam 6: ISR-Timer

ISR-Sijhawm
ISR-Sijhawm

#pragma vector = TIMER0_A0_VECTOR

_ cuam tshuam void Timer_A (tsis muaj dab tsi)

{

z ++;

yog (z> ncua)

{

P3OUT = code [x];

P6OUT = code1 [y];

x ++;

yog tias (x == 10)

{

x = 0;

y ++;

}

yog tias (y == 6)

y = 0;

z = 0;

}

}

pragma vector yog rau ISR sawv cev hauv C embd.

code [x] thiab code1 [y] yog cov arrays uas muaj cov txiaj ntsig tso tawm rau ob xya ntu, rau kev tso saib 60 vib nas this.

Kauj Ruam 7: Kho vajtse cuam tshuam

P2DIR = 0x00;

P2REN = 0x02;

P2OUT = 0x02;

P2IE | = BIT1;

P2IES | = BIT1;

P2IFG & = ~ BIT1;

Ntawm no P2.1 tau tshaj tawm tias yog kho vajtse cuam tshuam, yog tias khawm raug nias, lub txee rov ua dua tus nqi.

qhov kev zov me nyuam tau sau hauv ISR ntawm qhov cuam tshuam no.

Kauj Ruam 8: ISR- Pib dua/ Laub Khawm

#pragma vector = PORT2_VECTOR

_ cuam tshuam qhov tsis muaj chaw nres nkoj_2 (tsis muaj dab tsi)

{

P2IFG & = ~ BIT1;

x = 0; y = 0;

P3OUT = code [x];

P6OUT = code1 [y];

v ++;

rau (i = 0; i

{

P1OUT | = BIT0; //P1.0 = toggle

_delay_cycles (1048576);

P1OUT & = ~ BIT0; // P1.0 = toggle

_delay_cycles (1048576);

}

Qhov ISR no rov ua dua lub txee, thiab khaws qhov suav pes tsawg zaus qhov seem raug nias.

(Nov yog cov zaub tau ua los ntawm kev hloov pauv, tseem tuaj yeem siv lwm qhov array thiab lub sijhawm, los qhia cov txiaj ntsig raws li tso tawm hauv 7 ntu).

Kauj ruam 9: CODE

CODE
CODE

#suav nrog

#define ncua 1000

char code = {0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, 0xFE, 0xE6};

char code1 = {0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B};

volatile unsigned int x = 0, y = 0, z = 0;

volatile unsigned int v = 0, kuv = 0;

void lub ntsiab ()

{

WDTCTL = WDTPW | WDTHOLD; // nres lub moos timer

P7DIR | = 0xFF;

P7OUT | = 0x00;

P8DIR | = 0xFF;

P8OUT | = 0x00;

P4DIR | = 0xFF;

P4OUT | = 0x00;

P5DIR | = 0xFF;

P5OUT | = 0x00;

P1DIR = 0xFF;

P3DIR = 0xFF;

P6DIR = 0xFF;

P2DIR = 0x00;

P2REN = 0x02;

P2OUT = 0x02;

P2IE | = BIT1;

P2IES | = BIT1;

P2IFG & = ~ BIT1;

TA0CCTL0 = CCIE;

TA0CCR0 = 999;

TA0CTL = TASSEL_2 + MC_1;

_BIS_SR (LPM0_bits+GIE);

}

// Timer A0 cuam tshuam kev pabcuam niaj hnub

#pragma vector = TIMER0_A0_VECTOR

_ cuam tshuam void Timer_A (tsis muaj dab tsi)

{

z ++;

yog (z> ncua)

{

P3OUT = code [x];

P6OUT = code1 [y];

x ++;

yog tias (x == 10)

{

x = 0;

y ++;

}

yog tias (y == 6)

y = 0;

z = 0;

}

}

// Kho vajtse cuam tshuam kev pabcuam niaj hnub

#pragma vector = PORT2_VECTOR

_ cuam tshuam void chaw nres nkoj_2 (tsis muaj dab tsi)

{

P2IFG & = ~ BIT1;

x = 0;

y = 0;

P3OUT = code [x];

P6OUT = code1 [y];

v ++;

rau (i = 0; i

{P1OUT | = BIT0; // P1.0 = toggle

_day_cycles (1048576);

P1OUT & = ~ BIT0; // P1.0 = toggle

_day_cycles (1048576);

}

}

Kauj Ruam 10: Cov Cai Siv

Siv Txoj Cai
Siv Txoj Cai

GitHub Repository

Pom zoo: