最近因为有事情外出了几天,今天自己研究了板卡的裸机程序,因为使用的虚拟机一直没办法安装USBOTG的驱动,自己也很郁闷,所以就只在练习裸机程序。
自己以前没有学过嵌入式,这次也是在边学边玩板卡,这次自己试着把led流水灯点起来了,程序是这样的
void Gpio_LED1(uint8_t On)
{
if (On) {
MP0_4DAT_REG &= ~(1<
} else {
MP0_4DAT_REG |= (1<
}
}
void Gpio_LED2(uint8_t On)
{
if (On) {
MP0_4DAT_REG &= ~(1<
} else {
MP0_4DAT_REG |= (1<
}
}
void Gpio_LED3(uint8_t On)
{
if (On) {
MP0_4DAT_REG &= ~(1<
} else {
MP0_4DAT_REG |= (1<
}
}
void Gpio_LED4(uint8_t On)
{
if (On) {
MP0_4DAT_REG &= ~(1<
} else {
MP0_4DAT_REG |= (1<
}
}
void Gpio_Beep(uint8_t On)
{
if (On) {
GPD0DAT_REG |= (1<
} else {
GPD0DAT_REG &= ~(1<
}
}
void Gpio_Init(void)
{
// GPM04_4 output led1, off
MP0_4CON_REG = (MP0_4CON_REG & (~(0xf<<(LED1<<2)))) | (0x1<<(LED1<<2));
MP0_4DAT_REG |= (1<
// GPM04_5 output led2, off
MP0_4CON_REG = (MP0_4CON_REG & (~(0xf<<(LED2<<2)))) | (0x1<<(LED2<<2));
MP0_4DAT_REG |= (1<
// GPM04_6 output led3, off
MP0_4CON_REG = (MP0_4CON_REG & (~(0xf<<(LED3<<2)))) | (0x1<<(LED3<<2));
MP0_4DAT_REG |= (1<
// GPM04_7 output led4, off
MP0_4CON_REG = (MP0_4CON_REG & (~(0xf<<(LED4<<2)))) | (0x1<<(LED4<<2));
MP0_4DAT_REG |= (1<
// Beep output, off
GPD0CON_REG = (GPD0CON_REG & (~(0xf<<(BEEP<<2)))) | (0x1<<(BEEP<<2));
GPD0DAT_REG &= ~(1<
}
void main(void)
{
Gpio_Init();
while (1) {
Gpio_LED1(1);
Delay_ms(1000);
Gpio_LED1(0);
Gpio_LED2(1);
Delay_ms(1000);
Gpio_LED2(0);
Gpio_LED3(1);
Delay_ms(1000);
Gpio_LED3(0);
Gpio_LED4(1);
Gpio_Beep(1);
Delay_ms(1000);
Gpio_LED4(0);
Gpio_Beep(0);
}
}