找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

C8051f单片机配置软件(新手必备)

[复制链接]
admin 发表于 2012-9-2 06:18:37 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
Configuration Wizard支持的MCU有:

F00x, F01x, F02x, F04x, F06x, F12x, F13x, F2xx, F30x, F31x, F32x, F33x, F34x, F35x, F36x, F41x, F50x, F52xA, F53xA, F92x, F93x T60x, T61x and T63x
下面我以一个简单的例子来说明Configuration Wizard的使用方法。

试验器材:

C8051F340开发板(使用外部晶振22118400Hz) 1块

U-EC5仿真器 1个



试验目的:

利用C8051F340开发板上的UART1输出“hello”



第一步:打开Configuration Wizard程序,选择“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;
}

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');
}
}



第六步,keil编译完成后,下载程序,连接串口到PC,就可以看到输出“hello”。

C8051f单片机配置软件.zip (8.4 MB, 下载次数: 186)
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-12-31 03:55 , Processed in 0.067893 second(s), 13 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表