|
Configuration Wizard 2可以为Silicon Laboratories MCU自动生成初始化代码,简化了C8051F的开发,特别适合C8051F的初学者,你不需要再去寄那么多的寄存器名字.
Configuration Wizard 2目前支持的MCU有: Support for F00x, F01x, F02x, F04x, F06x, F12x, F13x, F2xx, F30x, F31x, F32x, F33x, F34A/B, F34x, F35x, F36x, F41x, F50x, F51x, F52xA, F53xA, F54x, F55x, F56x, F57x, F58x, F59x, F70x, F71x, F80x, F81x, F82x, F83x, F90x, F91x, F92x, F93x, F98x, F99x, T60x, T61x, T63x and Si10xx MCUs
可以从SILABS网站下载到最新版的Configuration Wizard 2
https://www.silabs.com/products/mcu/Pages/ConfigWizard.aspx
下面我以一个简单的例子来说明Configuration Wizard的使用方法。
试验目的:
利用C8051F340的UART1输出“hello!my friend!”
第一步:打开Configuration Wizard 2程序,选择“C8051F340”,如下图
然后按“OK”后,自动生成C8051F340的程序框架,如下图
第二步:设置生成C代码,在菜单“Options”中设置,如下图
第三步,配置开发板上的外围设备(如UART,SPI,Timer。。。)都可以在菜单“Peripherals”中完成,如图
1,配置Port I/O,菜单“Peripherals”-“Port I/O”。此处UART1使用了P0.2和P0.3,所以配置如下:
2,时钟配置,菜单“Peripherals”-“Oscillators”,使用外部时钟22118400Hz
3,关闭WDT功能,菜单“Peripherals”-“PCA”
4,UART设置,菜单“Peripherals”-“UART”,波特率设置为9600bps。
第四步,生成代码如下:
/////////////////////////////////////
// Generated Initialization File //
/////////////////////////////////////
#include "C8051F340.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void PCA_Init()
{
PCA0MD &= ~0x40;
PCA0MD = 0x00;
}
void UART_Init()
{
SBRLL1 = 0x80;
SBRLH1 = 0xFB;
SCON1 = 0x10;
SBCON1 = 0x43;
}
void Port_IO_Init()
{
// P0.0 - Skipped, Open-Drain, Digital
// P0.1 - Skipped, Open-Drain, Digital
// P0.2 - TX1 (UART1), Open-Drain, Digital
// P0.3 - RX1 (UART1), Open-Drain, Digital
// P0.4 - Unassigned, Open-Drain, Digital
// P0.5 - Unassigned, Open-Drain, Digital
// P0.6 - Skipped, Open-Drain, Analog
// P0.7 - Skipped, Open-Drain, Analog
// P1.0 - Unassigned, Open-Drain, Digital
// P1.1 - Unassigned, Open-Drain, Digital
// P1.2 - Unassigned, Open-Drain, Digital
// P1.3 - Unassigned, Open-Drain, Digital
// P1.4 - Unassigned, Open-Drain, Digital
// P1.5 - Unassigned, Open-Drain, Digital
// P1.6 - Unassigned, Open-Drain, Digital
// P1.7 - Unassigned, Open-Drain, Digital
// P2.0 - Unassigned, Open-Drain, Digital
// P2.1 - Unassigned, Open-Drain, Digital
// P2.2 - Unassigned, Open-Drain, Digital
// P2.3 - Unassigned, Open-Drain, Digital
// P2.4 - Unassigned, Open-Drain, Digital
// P2.5 - Unassigned, Open-Drain, Digital
// P2.6 - Unassigned, Open-Drain, Digital
// P2.7 - Unassigned, Open-Drain, Digital
// P3.0 - Unassigned, Open-Drain, Digital
// P3.1 - Unassigned, Open-Drain, Digital
// P3.2 - Unassigned, Open-Drain, Digital
// P3.3 - Unassigned, Open-Drain, Digital
// P3.4 - Unassigned, Open-Drain, Digital
// P3.5 - Unassigned, Open-Drain, Digital
// P3.6 - Unassigned, Open-Drain, Digital
// P3.7 - Unassigned, Open-Drain, Digital
P0MDIN = 0x3F;
P0SKIP = 0xC3;
XBR1 = 0x40;
XBR2 = 0x01;
}
void Oscillator_Init()
{
int i = 0;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
CLKSEL = 0x01;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
PCA_Init();
UART_Init();
Port_IO_Init();
Oscillator_Init();
}
第五步,添加main函数和串口输入函数
void uart1SendChar(unsigned char ch)
{
SBUF1 = ch;
while(SCON1&0x02==0)
;
SCON1 = SCON1&0xfd;
}
void main(void)
{
Init_Device();
while(1)
{
uart1SendChar('h');
uart1SendChar('e');
uart1SendChar('l');
uart1SendChar('l');
uart1SendChar('o');
uart1SendChar('!');
uart1SendChar('m');
uart1SendChar('y');
uart1SendChar(' ');
uart1SendChar('f');
uart1SendChar('r');
uart1SendChar('i');
uart1SendChar('e');
uart1SendChar('n');
uart1SendChar('d');
uart1SendChar('!');
}
}
第六步,keil编译完成后,下载程序,连接串口到PC,就可以看到输出。
|
|