本文介绍了C8051f312单片机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是在C语言非常好,但我有写一个很简单的code到C8051F312微控制器。
我的code不工作。请帮我做什么我错了。

 的#include C8051F310.h
的#include stdio.h中SBIT LED_16 = P1 ^ 7; //绿色LED:1 = ON; 0 = OFF无效的init(无效)
{
    //的XBRn registers_init
    XBR0 = 0×00;
    XBR1 = 0×00; //启用了横梁
    PCA0MD = 0X00;
    // port_init
    P0MDOUT = 0×00; //为P0输出配置
    P1MDOUT = 0X40; //为P1输出配置
    P2MDOUT = 0×00; //为P2输出配置
    P3MDOUT = 0×00; //为P3输出配置
}无效的主要(无效)
{
    在里面();    而(1)
    {
        LED_16 = 1; // LED连续点亮
    }
}


解决方案

所有1.首先,你应该使用2下列选项之一为的#include 指令

 的#include路径规范
#包括LT&;路径规格>

,而不是的#include路径规范,像你一样

P1 2.To一般configuire第7位I / O端口在推挽模式下工作,你应该设置

P1MDOUT = 0x80的;

,而不是

P1MDOUT = 0X40;

I'm not very good at C language, but I have write a very simple code to a C8051F312 microcontroller.My code doesn't working. Please help me what did I wrong.

#include C8051F310.h
#include stdio.h

sbit LED_16 = P1^7; // green LED: 1 = ON; 0 = OFF

void init(void)
{
    // XBRN registers_init
    XBR0 = 0x00;
    XBR1 = 0x00; // Enable the crossbar
    PCA0MD  = 0X00;


    // port_init
    P0MDOUT = 0x00; // Output configuration for P0
    P1MDOUT = 0x40; // Output configuration for P1
    P2MDOUT = 0x00; // Output configuration for P2
    P3MDOUT = 0x00; // Output configuration for P3
}

void main(void)
{
    init();

    while (1)
    {
        LED_16 = 1; // LED continuously illuminated
    }
}
解决方案

1.First of all you should use one of 2 following options for #include directive

#include  "path-spec"
#include  <path-spec>

, not #include path-spec, as you did

2.To configuire 7th bit of P1 general I/O port to work in push-pull mode you should set

P1MDOUT = 0x80;

, not

P1MDOUT = 0x40;

这篇关于C8051f312单片机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-05 05:47