找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 130|回复: 1
打印 上一主题 下一主题
收起左侧

这个怎么改成52的程序?

[复制链接]
跳转到指定楼层
楼主
ID:950193 发表于 2024-9-12 19:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "33A04.h"
void AiP33A04_Port_Init(void)
{
        CLK = 0;
        DIN = 0;
       
}
void AiP33A04_Write_Reg(unsigned char Current_Mode,unsigned char COM_Data,unsigned int SEG_Data)
{
        unsigned char i;
       
        /*传输16bit SEG数据*/
        for(i=0;i<16;i++)
        {
                CLK = 0;
                delay();
                if(SEG_Data & 0x0001 == 0x0001)
                        DIN = 1;
                else
                        DIN = 0;
                delay();
                CLK = 1;
                delay();
                SEG_Data = SEG_Data >> 1;
        }
       
        /*传输8bit COM数据*/
        for(i=0;i<8;i++)
        {
                CLK = 0;
                delay();
                if(COM_Data & 0x01 == 0x01)
                        DIN = 1;
                else
                        DIN = 0;
                delay();
                CLK = 1;
                delay();
                COM_Data=COM_Data>>1;
        }
       
        /*传输4bit 恒流选择*/
        for(i=0;i<4;i++)
        {
                CLK = 0;
                delay();
                if(Current_Mode & 0x1 == 0x1)
                        DIN = 1;
                else
                        DIN = 0;
                delay();
                CLK = 1;
                delay();
                Current_Mode = Current_Mode>>1;
        }
       
        /*传输2bit保留位*/
        for(i=0;i<2;i++)
        {
                CLK = 0;
                delay();
                DIN = 0;
                delay();
                CLK = 1;
                delay();
        }
}

void AiP33A04_Latch(void)
{
        CLK = 1;
        delay();
        DIN = 1;
        delay();
        DIN = 0;
        delay();
}
void AiP33A04_Stop(void)
{
        CLK = 0;
        delay();
        DIN = 1;
        delay();
        DIN = 0;
        delay();
}
void port_init()
{
          P0IO = 0xFF;            // direction
                P0PU = 0x00;            // pullup      P1PU &= ~0x3f;

                P0OD = 0x00;            // open drain
                P0DB = 0x00;            // bit7~6(debounce clock), bit5~0=P07~02 debounce
                P0   = 0x00;            // port initial value
               
                P1IO = 0xFF;            // direction
                P1PU = 0x00;            // pullup
                P1OD = 0x00;            // open drain
                P15DB = 0x00;           // debounce : P54, 52, 17, 16, 12, 11
                P1   = 0x00;            // port initial value
               
                P2IO = 0xFF;            // direction
                P2PU = 0x00;            // pullup
                P2OD = 0x00;            // open drain
                P2   = 0x00;            // port initial value
               
                P3IO = 0xFF;            // direction
                P3PU = 0x00;            // pullup
                P3   = 0x00;            // port initial value
               
                P4IO = 0xFF;            // direction
                P4PU = 0x00;            // pullup
                P4OD = 0x00;            // open drain
                P4   = 0x00;            // port initial value
               
                P5IO = 0xFF;            // direction
                P5PU = 0x00;            // pullup
                P5   = 0x00;            // port initial value
               
                // Set port functions
                P0FSRH = 0x00;          // P0 selection High
                P0FSRL = 0x00;          // P0 selection Low
                P1FSRH = 0x00;          // P1 selection High
                P1FSRL = 0x00;          // P1 selection Low
                P2FSRH = 0x00;          // P2 selection High
                P2FSRL = 0x00;          // P2 selection Low
                P3FSR = 0x00;           // P3 selection
                P4FSR = 0x00;           // P4 selection
                P5FSR = 0x00;           // P5 selection
}





#include "timer.h"
void Timer2_init()
{
        // initialize Timer2
        // T2ADRH = 0x07; T2ADRL = 0xcf;  period = 1mS
//  T2ADRH = 0x00; T2ADRL = 0xc7;  period = 0.1mS
        IE |= 0x80;
        IE2 |= 0x08;            // Enable Timer2 interrupt 定时器中断使能
        T2CRH |= 0x80;           // timer setting High
        T2CRL = 0x60;           // timer setting Low8分频
        T2ADRH = 0x00;          // period count High
        T2ADRL = 0xc7;          // period count Low
        T2CRH |= 0x01;           // timer setting High
}
void clock_init()
{
        // internal RC clock (16.000000MHz)
        OSCCR = 0x28;           // Set Int. OSC
        SCCR = 0x00;            // Use Int. OSC
}

void INT_Timer2() interrupt 15
{       
                s=s-1;
}


304.zip

95.66 KB, 下载次数: 0

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:344848 发表于 2024-9-13 01:10 | 只看该作者
   首先解释下面程序的含义,再谈如何转换
      // Set port functions
                P0FSRH = 0x00;          // P0 selection High
                P0FSRL = 0x00;          // P0 selection Low
                P1FSRH = 0x00;          // P1 selection High
                P1FSRL = 0x00;          // P1 selection Low
                P2FSRH = 0x00;          // P2 selection High
                P2FSRL = 0x00;          // P2 selection Low
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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