#include "STC12C5620AD.H" #include "EEPROM.H" #include "Channel_Handle.H" /********************** 声明外部变量**************************/ /********************** EEPROM 存储电台PLL*************************/ void EEPROM_Save_PLL(uchar Index,uint Udata) { uchar Temp_H; uchar Temp_L; //PLL转换缓存 uchar EEPROM_H; uchar EEPROM_L; //EEPROM读取缓存 Temp_H=Udata>>8; Temp_L=Udata%256; switch (Index) { case 1: EEPROM_H=EEPROM_Read_Byte(0x00,0x02); //暂存N0.8电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x00,0x03); //暂存N0.8电台PLL高位 EEPROM_Earse(0x00,0x00); //擦除第1扇区 EEPROM_Write_Byte(Temp_H,0x00,0x00); //写入N0.1电台PLL高位 EEPROM_Write_Byte(Temp_L,0x00,0x01); //写入N0.1电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x00,0x02); //写入N0.8电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x00,0x03); //写入N0.8电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 2: EEPROM_H=EEPROM_Read_Byte(0x02,0x02); //暂存N0.9电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x02,0x03); //暂存N0.9电台PLL高位 EEPROM_Earse(0x02,0x00); //擦除第2扇区 EEPROM_Write_Byte(Temp_H,0x02,0x00); //写入N0.2电台PLL高位 EEPROM_Write_Byte(Temp_L,0x02,0x01); //写入N0.2电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x02,0x02); //写入N0.9电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x02,0x03); //写入N0.9电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 3: EEPROM_H=EEPROM_Read_Byte(0x04,0x02); //暂存N0.10电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x04,0x03); //暂存N0.10电台PLL高位 EEPROM_Earse(0x04,0x00); //擦除第3扇区 EEPROM_Write_Byte(Temp_H,0x04,0x00); //写入N0.3电台PLL高位 EEPROM_Write_Byte(Temp_L,0x04,0x01); //写入N0.3电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x04,0x02); //写入N0.10电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x04,0x03); //写入N0.10电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 4: EEPROM_H=EEPROM_Read_Byte(0x06,0x02); //暂存N0.11电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x06,0x03); //暂存N0.11电台PLL高位 EEPROM_Earse(0x06,0x00); //擦除第4扇区 EEPROM_Write_Byte(Temp_H,0x06,0x00); //写入N0.4电台PLL高位 EEPROM_Write_Byte(Temp_L,0x06,0x01); //写入N0.4电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x06,0x02); //写入N0.11电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x06,0x03); //写入N0.11电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 5: EEPROM_H=EEPROM_Read_Byte(0x08,0x02); //暂存N0.12电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x08,0x03); //暂存N0.12电台PLL高位 EEPROM_Earse(0x08,0x00); //擦除第5扇区 EEPROM_Write_Byte(Temp_H,0x08,0x00); //写入N0.5电台PLL高位 EEPROM_Write_Byte(Temp_L,0x08,0x01); //写入N0.5电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x08,0x02); //写入N0.12电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x08,0x03); //写入N0.12电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 6: EEPROM_H=EEPROM_Read_Byte(0x0a,0x02); //暂存N0.13电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x0a,0x03); //暂存N0.13电台PLL高位 EEPROM_Earse(0x0a,0x00); //擦除第6扇区 EEPROM_Write_Byte(Temp_H,0x0a,0x00); //写入N0.6电台PLL高位 EEPROM_Write_Byte(Temp_L,0x0a,0x01); //写入N0.6电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x0a,0x02); //写入N0.13电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x0a,0x03); //写入N0.13电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 7: EEPROM_H=EEPROM_Read_Byte(0x0c,0x02); //暂存N0.14电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x0c,0x03); //暂存N0.14电台PLL高位 EEPROM_Earse(0x0c,0x00); //擦除第7扇区 EEPROM_Write_Byte(Temp_H,0x0c,0x00); //写入N0.7电台PLL高位 EEPROM_Write_Byte(Temp_L,0x0c,0x01); //写入N0.7电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x0c,0x02); //写入N0.14电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x0c,0x03); //写入N0.14电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 8: EEPROM_H=EEPROM_Read_Byte(0x00,0x00); //暂存N0.1电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x00,0x01); //暂存N0.1电台PLL高位 EEPROM_Earse(0x00,0x00); //擦除第1扇区 EEPROM_Write_Byte(Temp_H,0x00,0x02); //写入N0.8电台PLL高位 EEPROM_Write_Byte(Temp_L,0x00,0x03); //写入N0.8电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x00,0x00); //写入N0.1电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x00,0x01); //写入N0.1电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 9: EEPROM_H=EEPROM_Read_Byte(0x02,0x00); //暂存N0.2电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x02,0x01); //暂存N0.2电台PLL高位 EEPROM_Earse(0x02,0x00); //擦除第2扇区 EEPROM_Write_Byte(Temp_H,0x02,0x02); //写入N0.9电台PLL高位 EEPROM_Write_Byte(Temp_L,0x02,0x03); //写入N0.9电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x02,0x00); //写入N0.2电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x02,0x01); //写入N0.2电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 10: EEPROM_H=EEPROM_Read_Byte(0x04,0x00); //暂存N0.3电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x04,0x01); //暂存N0.3电台PLL高位 EEPROM_Earse(0x04,0x00); //擦除第3扇区 EEPROM_Write_Byte(Temp_H,0x04,0x02); //写入N0.10电台PLL高位 EEPROM_Write_Byte(Temp_L,0x04,0x03); //写入N0.10电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x04,0x00); //写入N0.3电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x04,0x01); //写入N0.3电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 11: EEPROM_H=EEPROM_Read_Byte(0x06,0x00); //暂存N0.4电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x06,0x01); //暂存N0.4电台PLL高位 EEPROM_Earse(0x06,0x00); //擦除第4扇区 EEPROM_Write_Byte(Temp_H,0x06,0x02); //写入N0.11电台PLL高位 EEPROM_Write_Byte(Temp_L,0x06,0x03); //写入N0.11电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x06,0x00); //写入N0.4电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x06,0x01); //写入N0.4电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 12: EEPROM_H=EEPROM_Read_Byte(0x08,0x00); //暂存N0.5电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x08,0x01); //暂存N0.5电台PLL高位 EEPROM_Earse(0x08,0x00); //擦除第5扇区 EEPROM_Write_Byte(Temp_H,0x08,0x02); //写入N0.12电台PLL高位 EEPROM_Write_Byte(Temp_L,0x08,0x03); //写入N0.12电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x08,0x00); //写入N0.5电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x08,0x01); //写入N0.5电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 13: EEPROM_H=EEPROM_Read_Byte(0x0a,0x00); //暂存N0.6电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x0a,0x01); //暂存N0.6电台PLL高位 EEPROM_Earse(0x0a,0x00); //擦除第6扇区 EEPROM_Write_Byte(Temp_H,0x0a,0x02); //写入N0.13电台PLL高位 EEPROM_Write_Byte(Temp_L,0x0a,0x03); //写入N0.13电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x0a,0x00); //写入N0.6电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x0a,0x01); //写入N0.6电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 14: EEPROM_H=EEPROM_Read_Byte(0x0c,0x00); //暂存N0.7电台PLL高位 EEPROM_L=EEPROM_Read_Byte(0x0c,0x01); //暂存N0.7电台PLL高位 EEPROM_Earse(0x0c,0x00); //擦除第7扇区 EEPROM_Write_Byte(Temp_H,0x0c,0x02); //写入N0.14电台PLL高位 EEPROM_Write_Byte(Temp_L,0x0c,0x03); //写入N0.14电台PLL低位 EEPROM_Write_Byte(EEPROM_H,0x0c,0x00); //写入N0.7电台PLL高位 EEPROM_Write_Byte(EEPROM_L,0x0c,0x01); //写入N0.7电台PLL低位 EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 break; case 15: EEPROM_Earse(0x0e,0x00); //擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 EEPROM_Write_Byte(Temp_H,0x0e,0x02); //写入N0.15电台PLL高位 EEPROM_Write_Byte(Temp_L,0x0e,0x03); //写入N0.15电台PLL低位 break; default: break; } } /********************** EEPROM 读取电台PLL*************************/ uint EEPROM_Get_PLL(uchar Index) { uint PLL_Temp; uchar Temp_H; uchar Temp_L; switch (Index) { case 1: //NO.1电台PLL Temp_H=EEPROM_Read_Byte(0x00,0x00); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x00,0x01); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 2: //NO.2电台PLL Temp_H=EEPROM_Read_Byte(0x02,0x00); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x02,0x01); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 3: //NO.3电台PLL Temp_H=EEPROM_Read_Byte(0x04,0x00); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x04,0x01); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 4: //NO.4电台PLL Temp_H=EEPROM_Read_Byte(0x06,0x00); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x06,0x01); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 5: //NO.5电台PLL Temp_H=EEPROM_Read_Byte(0x08,0x00); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x08,0x01); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 6: //NO.6电台PLL Temp_H=EEPROM_Read_Byte(0x0a,0x00); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x0a,0x01); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; case 7: //NO.7电台PLL Temp_H=EEPROM_Read_Byte(0x0c,0x00); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x0c,0x01); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 8: //NO.8电台PLL Temp_H=EEPROM_Read_Byte(0x00,0x02); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x00,0x03); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 9: //NO.9电台PLL Temp_H=EEPROM_Read_Byte(0x02,0x02); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x02,0x03); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 10: //NO.10电台PLL Temp_H=EEPROM_Read_Byte(0x04,0x02); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x04,0x03); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 11: //NO.11电台PLL Temp_H=EEPROM_Read_Byte(0x06,0x02); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x06,0x03); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 12: //NO.12电台PLL Temp_H=EEPROM_Read_Byte(0x08,0x02); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x08,0x03); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 13: //NO.13电台PLL Temp_H=EEPROM_Read_Byte(0x0a,0x02); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x0a,0x03); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 14: //NO.14电台PLL Temp_H=EEPROM_Read_Byte(0x0c,0x02); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x0c,0x03); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; case 15: //NO.15电台PLL Temp_H=EEPROM_Read_Byte(0x0e,0x02); //获取PLL高位 Temp_L=EEPROM_Read_Byte(0x0e,0x03); //获取PLL高位 PLL_Temp=Temp_H<<8|Temp_L; break; default: break; } return PLL_Temp; } /********************** EEPROM 读取最后一次序号*************************/ uchar EEPROM_Get_Index() { uchar Index; Index=EEPROM_Read_Byte(0x0e,0x00); return Index; } /********************** EEPROM 写入最后一次序号*************************/ void EEPROM_Write_Index(uchar Index) { EEPROM_Earse(0x0e,0x00); //首先擦除第8扇区 EEPROM_Write_Byte(Index,0x0e,0x00); //写入电台序号 }
上一篇:24C02单片机编程的一点注意问题
下一篇:什么叫RAM?什么叫ROM?其主要的功能是什么?
推荐阅读最新更新时间:2024-03-16 14:23