世俱杯 2025

登录 免费注册 世俱杯 2025 | 行业黑名单 | 帮助
维库电子市场网
技术交流 | 电路欣赏 | 工控天地 | 数字广电 | 通信技术 | 电源技术 | 测控之家 | EMC技术 | ARM技术 | EDA技术 | PCB技术 | 嵌入式系统
驱动编程 | 集成电路 | 器件替换 | 模拟技术 | 新手园地 | 单 片 机 | DSP技术 | MCU技术 | IC 设计 | IC 产业 | CAN-bus/DeviceNe

pcf8563t与mega128的系统下twi通讯怎么不行呀?

作者:fzm 栏目:单片机
PCF8563TMEGA128的系统下twi通讯怎么不行呀?
这是我的部分有关程序,请指点一下,我搞不定呀!

void port_init(void)
{   ···  
    DDRD = 0xf0;
    PORTD = 0x0f;
    ···
}

void twi_init(void)
{
    TWCR = 0X00; //disable twi
    TWBR = 0x7b; //set bit rate
    TWDR = 0xff;
    TWSR = 0x01; //set prescale
    TWAR = 0x00; //set slave address
    TWCR = 0x04; //enable twi
}

#pragma interrupt_handler twi_isr:34
void twi_isr(void)
{
    static unsigned CHAR TWI_s;
    num ++;//对中断计数
    if(num > 255) num = 0;
    SWITCH (TWSR & 0xf8){
        case TWI_START:             //0x08 START has been transmitted  
        case TWI_REP_START:         //0x10 Repeated START has been transmitted
            TWI_s = 0;        // Set buffer pointer to the TWI Address location
        case TWI_MTX_ADR_ACK:       //0x18 SLA+W has been tramsmitted and ACK received
        case TWI_MTX_DATA_ACK:      //0x28 Data byte has been tramsmitted and ACK received
            if (TWI_s < TWI_Size){
                TWDR = TWI_buf[TWI_s];
                TWI_s ++;
                TWCR = (1<<TWEN)|         // TWI Interface enabled
                    (1<<TWIE)|(1<<TWINT)| // Enable TWI Interupt and clear the flag to send byte
                    (0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|           //
                    (0<<TWWC);                                 //  
           }
           else                    // Send STOP after last byte
           {
               TWI_statusReg_lastTransOK = TRUE;                 // Set status bits to completed successfully.
               TWCR = (1<<TWEN)|                                 // TWI Interface enabled
                   (0<<TWIE)|(1<<TWINT)|                      // Disable TWI Interrupt and clear the flag
                   (0<<TWEA)|(0<<TWSTA)|(1<<TWSTO)|           // Initiate a STOP condition.
                   (0<<TWWC);                                 //
            }
            break;
        case TWI_MRX_DATA_ACK:      //0x50 Data byte has been received and ACK tramsmitted
            TWI_buf[TWI_s ++] = TWDR;
            TWI_s ++;
        case TWI_MRX_ADR_ACK:       //0x40 SLA+R has been tramsmitted and ACK received
            if (TWI_s < (TWI_Size - 1) )                  // Detect the last byte to NACK it.
            {
                TWCR = (1<<TWEN)|                                 // TWI Interface enabled
                    (1<<TWIE)|(1<<TWINT)|                      // Enable TWI Interupt and clear the flag to read next byte
                    (1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|           // Send ACK after reception
                    (0<<TWWC);                                 //  
             }
             else                    // Send NACK after next reception
             {
                 TWCR = (1<<TWEN)|                     &n
2楼: >>参与讨论
sflfw
好像没初始化端口
 
参与讨论
昵称:
讨论内容:
 
 
相关帖子
高手再帮我看看GCC的输出是怎么回事?
请教ATTINY2313替代90S2313问题?
大家帮我看看这个程序对不对!
有人用过青云的段式LCD模块吗,我试了好几片都没调出来。
大家帮我看看这个程序有没有错误


Copyright © 1998-2006 tgdrjb.cn 浙ICP证030469号