/*rtc晶元為pt7c4302*/
/*pt7c4302晶元的讀寫時序與rtc晶元ds1320基本一致*/
#define pt7c4302_sda_gpio_pin 30
#define pt7c4302_scl_gpio_pin 31
#define pt7c4302_rst_gpio_pin 36
#define pt7c4302_sda pt7c4302_sda_gpio_pin
#define pt7c4302_scl pt7c4302_scl_gpio_pin
#define pt7c4302_rst pt7c4302_rst_gpio_pin
/*讀暫存器位址*/
#define read_second_reg_addr 0x81
#define read_minute_reg_addr 0x83
#define read_hour_reg_addr 0x85
#define read_date_reg_addr 0x87
#define read_month_reg_addr 0x89
#define read_days_of_week_reg_addr 0x8b
#define read_year_reg_addr 0x8d
#define read_control_reg_addr 0x8f
/*寫暫存器位址*/
#define write_second_reg_addr 0x80
#define write_minute_reg_addr 0x82
#define write_hour_reg_addr 0x84
#define write_date_reg_addr 0x86
#define write_month_reg_addr 0x88
#define write_days_of_week_reg_addr 0x8a
#define write_year_reg_addr 0x8c
#define write_control_reg_addr 0x8e
void pt7c4302_init(void)
static void pt7c4302_write(unsigned char addr, unsigned char data)
else
addr >>= 1;
ithdelay(1);
ithgpioset(pt7c4302_scl);
ithdelay(1); //在sclk的上公升沿寫入資料位
ithgpioclear(pt7c4302_scl);
ithdelay(1);
}for (int n = 0; n < 8; n++) //將指定內容寫入該位址
else
data >>= 1;
ithdelay(1);
ithgpioset(pt7c4302_scl);
ithdelay(1); //在sclk的上公升沿寫入資料位
ithgpioclear(pt7c4302_scl);
ithdelay(1);
}ithgpioclear(pt7c4302_rst);
ithdelay(1);
}static unsigned char pt7c4302_read(unsigned char addr)
else
addr >>= 1;
ithdelay(1);
ithgpioset(pt7c4302_scl);
ithdelay(1); //在sclk的上公升沿寫入資料位
ithgpioclear(pt7c4302_scl);
ithdelay(1);
}ithgpiosetin(pt7c4302_sda);
ithdelay(1);
dat = 0;
tmp = 0;
for (int n = 0; n < 8; n++) //讀出該位址的資料
ithgpioclear(pt7c4302_rst);
ithgpiosetout(pt7c4302_sda);
ithdelay(1);
ithgpioset(pt7c4302_rst);
ithdelay(1);
ithgpioclear(pt7c4302_rst);
ithdelay(3);
// printf("\npt7c4302_read:dat= %x\n", dat);
return dat;
}/* examples
pt7c4302_write(write_control_reg_addr, 0x00);//允許寫操作
pt7c4302_write(write_year_reg_addr, 0x20);//2023年
pt7c4302_write(write_month_reg_addr, 0x08);//8月
pt7c4302_write(write_date_reg_addr, 0x29);//29日
pt7c4302_write(write_hour_reg_addr, 0x14);//14點
pt7c4302_write(write_minute_reg_addr, 0x55);//55分
pt7c4302_write(write_second_reg_addr, 0x30);//30秒
pt7c4302_write(write_control_reg_addr, 0x80);//禁止寫操作
*/void set_rtc_time(rtc_time_struct *time)
void read_rtc_time(rtc_time_struct *time)
/*bcd碼轉十進位制*/
unsigned char bcdtodex(unsigned char bcd_data)
/*十進位制轉bcd碼*/
unsigned char dextobcd(unsigned char dex)
/*讀取rtc時間,用來設定系統時間*/
void setsystemtimebyrtc(void)
tv.tv_sec = mktime(&system_time);
tv.tv_usec = 0;
settimeofday(&tv, null);
}
Codeforces 976E 題解報告
1 當把所有的倍數2 a都加到同一health上,health增加的最多 2 先計算每乙個creature的hp dmg,按該值對所有的creature排序 再求和,i include using namespace std const int n 200 1000 9 int hp n dmg n...
基於E2P讀寫的CRC 16校驗
在除錯客戶使用平台下 測試出e2p讀crc校驗碼的bug。在客戶重複上電的情況下,讀e2p crc校驗資料不匹配,導致設定預設引數資料進行系統初始化。此問題開始沒有重視,最終測試到時crc校驗出錯。以下是crc原理,演算法可以不用太了解。一 什麼是crc校驗 迴圈校驗碼 jyclic redunda...
E8卡linux系統讀寫高通字型檔晶元
e8卡linux系統讀寫高通字型檔晶元,在e8卡上通過linux的spi驅動讀寫高通字型檔晶元。spi是分主從的,字型檔晶元不會主動通過spi傳送資料。只有在linux上發起讀操作的時候,字型檔才會把他的資料傳送出來。spi mode ret ioctl fd,spi ioc wr mode,mod...