打印
[MCU]

有个程序准备用C8051F300,可总是不行,大神们帮忙看看

[复制链接]
1365|14
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
面包所长|  楼主 | 2016-5-29 14:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
程序我在STC12C5A60S2,运行正常,烧进C8051F300就不行,按照官方的端口配置软件也搞了,还是不行。
#include <stdio.h>
#include "compiler_defs.h"
#include "C8051F300_defs.h"

// Peripheral specific initialization functions,
// Called from the Init_Device() function
void PCA_Init()
{
    PCA0MD    &= ~0x40;
    PCA0MD    = 0x00;
}

void Port_IO_Init()
{

    P0MDOUT   = 0x0F;
    XBR2      = 0x40;
}

void Oscillator_Init()
{
    OSCICN    = 0x00;
}
void Init_Device(void)
{
    PCA_Init();
    Port_IO_Init();
    Oscillator_Init();
}
sbit SCLOCK=P0^0;
sbit DATA=P0^1;
sbit LE=P0^2;
sbit CE=P0^3;

void delay(int);

void main()
{
        unsigned long int registe0,registe1,registe2,temp1;
        int i;

        registe0=0x3000c9;                        //R Register
        registe1=0x4ff904;                        //C Register
        registe2=0x2ee02;                        //N Register
       
        temp1=0x800000;

        CE=1;                                        //Update R Latch, the writing order should be R, C, N
        SCLOCK=1;
        DATA=0;
        LE=0;
       
          for(i=0;i<24;i++)               
        {
                if((temp1&registe0)==0x0)               
                        DATA=0;
                else
                        DATA=1;
                SCLOCK=0;
                SCLOCK=1;

                temp1=temp1>>1;
        }
        temp1=0x800000;
        LE=1;
        LE=0;

        for(i=0;i<24;i++)                        //Update C Latch       
        {
                if((temp1&registe1)==0x0)               
                        DATA=0;
                else
                        DATA=1;
                SCLOCK=0;
                SCLOCK=1;

                temp1=temp1>>1;
        }
        temp1=0x800000;
        LE=1;
        LE=0;

        delay(5000);                                //interval between programming C and N register needs to be at least 5ms

        for(i=0;i<24;i++)                        //Update N Register
        {
                if((temp1&registe2)==0x0)               
                        DATA=0;
                else
                        DATA=1;
                SCLOCK=0;
                SCLOCK=1;

                temp1=temp1>>1;
        }
        temp1=0x800000;
        LE=1;
        while(1);
}

void delay(int length)
{
while (length >=0)
    length--;
}

相关下载

相关帖子

沙发
面包所长|  楼主 | 2016-5-29 17:41 | 只看该作者
主要就是端口初始化配置搞不清楚  求助啊

使用特权

评论回复
板凳
yhn1973| | 2016-5-29 22:05 | 只看该作者
你这端口配置就设置个输出模式,还有什么搞不清,看自己需要推挽输出还是开漏输出就行了。另外看你主程序中并没有调用初始化程序

使用特权

评论回复
地板
面包所长|  楼主 | 2016-5-30 13:47 | 只看该作者
yhn1973 发表于 2016-5-29 22:05
你这端口配置就设置个输出模式,还有什么搞不清,看自己需要推挽输出还是开漏输出就行了。另外看你主程序中 ...

我也不知道自己需要推挽还是开漏输出,就是把这些数据送到一个芯片的寄存器中,另外主程序中怎么调用初始化程序?我感觉已经调用啦?

使用特权

评论回复
5
yhn1973| | 2016-5-30 22:29 | 只看该作者
如果那个芯片是3.3V供电就用推挽输出,5V供电并且是CMOS电平就用开漏输出并外加上拉电阻。你主程序中并没有Init_Device()函数,怎么调用的初始化

使用特权

评论回复
6
ningling_21| | 2016-5-31 11:51 | 只看该作者
面包所长 发表于 2016-5-30 13:47
我也不知道自己需要推挽还是开漏输出,就是把这些数据送到一个芯片的寄存器中,另外主程序中怎么调用初始 ...

主程序在哪调用的初始化程序?

使用特权

评论回复
7
面包所长|  楼主 | 2016-5-31 14:42 | 只看该作者
ningling_21 发表于 2016-5-31 11:51
主程序在哪调用的初始化程序?

麻烦能说明白点吗?对单片机不是很熟悉 小白一枚

使用特权

评论回复
8
ningling_21| | 2016-5-31 15:14 | 只看该作者
面包所长 发表于 2016-5-31 14:42
麻烦能说明白点吗?对单片机不是很熟悉 小白一枚

你的程序太乱

程序结构示例:
main()
{
   ... //初始化代码
   ...
   ...//初始化代码

   while(1)
  {
     ...//主循环代码
}

}

使用特权

评论回复
9
面包所长|  楼主 | 2016-6-2 14:15 | 只看该作者
ningling_21 发表于 2016-5-31 15:14
你的程序太乱

程序结构示例:

大神可以留下个联系方式吗?我想请教下你

使用特权

评论回复
10
面包所长|  楼主 | 2016-6-2 15:22 | 只看该作者
ningling_21 发表于 2016-5-31 15:14
你的程序太乱

程序结构示例:

这是我要移植的原始程序,本来用的是ADUC841,现在用F300,怎么改呢?大神
#include <stdio.h>
#include <ADuC841.h>
sbit DATA=P3^3;        
sbit SCLOCK=P3^4;
sbit LATCH=P3^5;
sbit CE=P3^7;

void delay(int);

void main()
{
        unsigned long int registe0,registe1,registe2,temp1;
        int i;

        registe0=0x300029;                        //R Register
        registe1=0x0ff100;                        //C Latch        
        registe2=0x007802;                        //N Register
        
        temp1=0x800000;

        CE=1;                                        //Update R Latch        the order of writing the registers should be R,C,N
        SCLOCK=1;
        DATA=0;
        LATCH=0;
          for(i=0;i<24;i++)               
        {
                if((temp1&registe0)==0x0)               
                        DATA=0;
                else
                        DATA=1;
                SCLOCK=0;
                SCLOCK=1;

                temp1=temp1>>1;
        }
        temp1=0x800000;
        LATCH=1;
        LATCH=0;

        for(i=0;i<24;i++)                        //Update C Latch        
        {
                if((temp1&registe1)==0x0)               
                        DATA=0;
                else
                        DATA=1;
                SCLOCK=0;
                SCLOCK=1;

                temp1=temp1>>1;
        }
        temp1=0x800000;
        LATCH=1;        
        LATCH=0;        

        delay(5000);                                //interval between programming C and N register needs to be at least 15ms

                        
        for(i=0;i<24;i++)                        //Update N Register               
        {
                if((temp1&registe2)==0x0)               
                        DATA=0;
                else
                        DATA=1;
                SCLOCK=0;
                SCLOCK=1;

                temp1=temp1>>1;
        }
        temp1=0x800000;
        LATCH=1;
        while(1);
}

void delay(int length)
{
while (length >=0)
    length--;
}

使用特权

评论回复
11
yhn1973| | 2016-6-2 17:26 | 只看该作者
你需要补的是C语言的基础知识,你主程序中没调用Init_Device函数,Init_Device函数怎么可能执行,Init_Device函数没执行又怎么可能初始化

使用特权

评论回复
12
gx_huang| | 2016-6-4 10:39 | 只看该作者
呵呵,同意!

使用特权

评论回复
13
面包所长|  楼主 | 2016-6-6 16:59 | 只看该作者
yhn1973 发表于 2016-6-2 17:26
你需要补的是C语言的基础知识,你主程序中没调用Init_Device函数,Init_Device函数怎么可能执行,Init_Devi ...

哦 这样啊 C语言的基础确实不行 第一次实际接触这些

使用特权

评论回复
14
面包所长|  楼主 | 2016-6-8 15:03 | 只看该作者
求助

使用特权

评论回复
15
面包所长|  楼主 | 2016-6-14 14:39 | 只看该作者
谢谢大家的意见  我自己解决了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

32

帖子

0

粉丝