main.h
#ifndef SOURCES_MAIN_H_
#define SOURCES_MAIN_H_
#ifndef uint32_t
typedef __UINT32_TYPE__ uint32_t;
#endif
#define SIM_SCGC5 *(volatile uint32_t *)=0x40048038U
#define GPIOA_PDDR *(volatile uint32_t *)=0x400FF014U
#define GPIOA_PSOR *(volatile uint32_t *)=0x400FF004U
#define GPIOA_PCOR *(volatile uint32_t *)=0x400FF008U
#define PORTA_PCR2 *(volatile uint32_t *)=0x40049008U
#define PORTA_PCR1 *(volatile uint32_t *)=0x40049004U
#define GPIOD_PDDR *(volatile uint32_t *)=0x400FF0D4U
#define GPIOD_PSOR *(volatile uint32_t *)=0x400FF0C4U
#define GPIOD_PCOR *(volatile uint32_t *)=0x400FF0C8U
#define PORTD_PCR5 *(volatile uint32_t *)=0x4004C014U
#define GPIOD_PTOR *(volatile uint32_t *)=0x400FF0CCU
#define GPIOA_PTOR *(volatile uint32_t *)=0x400FF00CU
#endif /* SOURCES_MAIN_H_ */
main.c
#include "main.h"
void Delay(int n)
{
for(int i = 0;i<n;i++)
{
__asm("nop");
}
}
void setup()
{
SIM_SCGC5 = 0x00001200U;
GPIOA_PDDR = 0x00000006U;
GPIOD_PDDR = 0x00000020U;
PORTA_PCR2 = 0x00000124U;
PORTA_PCR1 = 0x00000124U;
PORTD_PCR5 = 0x00000124U;
}
void loop()
{
while(1)
{
GPIOA_PCOR = 0x00000002U; //RED on
Delay(1000000);
GPIOA_PSOR = 0x00000002U;//RED off
Delay(1000000);
GPIOA_PCOR = 0x00000004U;//GREEN on
Delay(1000000);
GPIOA_PSOR = 0x00000004U;//GREEN off
Delay(1000000);
GPIOD_PCOR = 0x00000020U;//BLUE on
Delay(1000000);
GPIOD_PSOR = 0x00000020U;//BLUE off
Delay(1000000);
GPIOA_PCOR = 0x00000006U; //YELLOW on
Delay(1000000);
GPIOA_PSOR = 0x00000006U;//YELLOW off
Delay(1000000);
/*cyan-blue 青色 on*/
GPIOD_PCOR = 0x00000020U;
GPIOA_PCOR = 0x00000004U;
Delay(1000000);
/*cyan-blue 青色 off*/
GPIOD_PSOR = 0x00000020U;
GPIOA_PSOR = 0x00000004U;
Delay(1000000);
/*PURPLE on*/
GPIOD_PCOR = 0x00000020U;
GPIOA_PCOR = 0x00000002U;
Delay(1000000);
/*PURPLE off*/
GPIOD_PSOR = 0x00000020U;
GPIOA_PSOR = 0x00000002U;
Delay(1000000);
/*WHITE on*/
GPIOA_PCOR = 0x00000002U;
GPIOA_PCOR = 0x00000004U;
GPIOD_PCOR = 0x00000020U;
Delay(1000000);
/*WHITE off*/
GPIOA_PSOR = 0x00000002U;
GPIOA_PSOR = 0x00000004U;
GPIOD_PSOR = 0x00000020U;
Delay(1000000);
}
}
int main(void)
{
setup();
loop();
return 0;
}
------程式碼結束--------