⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 programresetpolarity.c

📁 一个AVR单片机at17c85的系统程序
💻 C
字号:
// ProgramResetPolarity.c
// Locations 0x20000 through 0x20003 are used to store the reset/ouput enable polarity.
// 0xff = active high reset and active low output enable.
// 0x00 = active low reset and active high output enable.
// So the memory location values determine the reset polarity.
// After programming the data polling method is used to determine the end of 
// the internal programming cycle.
// Timer/Counter1 is used to ensure the polling code exits its while loop.

#include "at17c.h"

extern volatile unsigned char t1_timed_out;
 
extern unsigned char SendByte(unsigned char byte, unsigned char order);
extern void SendStartBit(void);
extern void SendStopBit(void);
 
void ProgramResetPolarity(unsigned char state) {

unsigned char i;
unsigned char test_ack = 0xff;

    PORTB &= 0xfb; // bring SER_EN low

    SendStartBit();
    SendByte(AT17C010 + WRITE,MSB_FIRST);  // send device address byte
    SendByte(0x00,MSB_FIRST);                 // 1st address byte
    SendByte(0x00,MSB_FIRST);                 // 2nd address byte
    SendByte(0x02,MSB_FIRST);                 // 3rd address byte ... most significant byte
 
    for (i = 0; i < 4; i++)
        SendByte(state,LSB_FIRST);
            
    SendStopBit();

    t1_timed_out = FALSE; // set in timer counter 0 overflow interrupt routine
 
    // 20 milli-second timeout
    // 7.3728MHz / 1024 = 7200 Hz
    // 7200 Hz = 138.8 us
    // 20 ms / 138.8 us = 144.09
    // 65536 - 144 = 65392 = ff70
    // interrupt on ffff to 0000 transition
    TCNT1H = 0xff;  
    TCNT1L = 0x70; // load counter
    TCCR1B = 0x05; // timer/counter 1 clock / 1024

    // continue sending start bit and device address until we get an ack back
    // data poll to program complete ... time out for error
    while (test_ack && !t1_timed_out) {
        SendStartBit();
        test_ack = SendByte(AT17C010 + WRITE,MSB_FIRST); // send device address byte
    }
    SendStopBit();

    PORTB |= 0x04; // bring SER_EN high
        
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -