這是一個單片機控制的收音機程序完整代碼和原理圖下載地址:http://www.51hei.com/bbs/dpj-19294-1.html下面我我截圖的一個子程序.#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轉(zhuǎn)換緩存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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)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扇區(qū)EEPROM_Write_Byte(Index,0x0e,0x00); //寫入電臺序號 break;case 15:EEPROM_Earse(0x0e,0x00); //擦除第8扇區(qū)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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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電臺PLLTemp_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扇區(qū)EEPROM_Write_Byte(Index,0x0e,0x00); //寫入電臺序號}
評論