嵌入式粤嵌开发板爱心代码
时间: 2023-10-05 20:09:20 浏览: 217
以下是一个简单的嵌入式粤嵌开发板爱心代码的示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stc12c5a60s2.h"
#define FOSC 11059200L
#define BAUD 9600
#define LED P1
void delay(unsigned int xms)
{
unsigned int i, j;
for (i = xms; i > 0; i--)
for (j = 112; j > 0; j--);
}
void uart_init()
{
SCON = 0x50;
TMOD &= 0x0F;
TMOD |= 0x20;
TH1 = TL1 = FOSC / 12 / BAUD;
TR1 = 1;
}
void uart_send(char dat)
{
SBUF = dat;
while (!TI);
TI = 0;
}
void main()
{
uart_init();
LED = 0xff;
while (1)
{
LED = 0x81;
delay(500);
LED = 0x42;
delay(500);
LED = 0x24;
delay(500);
LED = 0x18;
delay(500);
uart_send('I');
uart_send(' ');
uart_send('L');
uart_send('O');
uart_send('V');
uart_send('E');
uart_send(' ');
uart_send('Y');
uart_send('O');
uart_send('U');
uart_send('!');
}
}
```
该代码使用了STC12C5A60S2芯片进行开发,实现了在一组LED上显示一个闪烁的爱心,并使用串口输出"I LOVE YOU!"的信息。
阅读全文