Browsing this Thread:
1 Anonymous Users
|
Re: 關於I2C的程式
|
|
新會員
Joined
: 2005/3/2 22:45 最後登入時間
: 2006/9/14 18:08
Group:
註冊會員
Level : 2 HP : 0 / 49 MP : 6 / 2833 EXP : 97
|
感謝各位大大~ 問題找到了~ 原因是....PIC壞掉了...Orz
發表於: 2005/8/10 23:58
|
|
|
Re: 關於I2C的程式
|
|
高級會員
Joined
: 2004/11/23 21:03 最後登入時間
: 2007/8/6 10:12
From 需要多些人性的地方
Group:
註冊會員
Level : 7 HP : 0 / 158 MP : 23 / 9213 EXP : 34
|
1. 先不用 ICD2 看看編譯有問題嗎 2. 試試 ICD2 連線是否正常 3.隨便燒錄一個程式 看看是否 ICD2 正常 4. IC 設定值有確認了嗎 5. Erase IC 再燒錄 6.換一顆IC 試試 7.換一個 ICD2 試試
看起來 像是 燒錄失敗
發表於: 2005/8/10 22:32
|
IWC IWC JL Rolex
PP 有點距離 越來越遠
|
|
Re: 關於I2C的程式
|
|
資深會員
Joined
: 2004/10/10 23:28 最後登入時間
: 2015/7/30 16:42
Group:
註冊會員
Level : 14 HP : 0 / 329 MP : 76 / 19245 EXP : 17
|
project 中所加入的.lkr檔,是不是mcc18底下的18f452i.lkr呢?
其中的 'i' 代表適合ICD2使用;使用mcc18底下的,是因為搭配c18的記憶體分配。
發表於: 2005/8/10 22:32
|
|
|
關於I2C的程式
|
|
新會員
Joined
: 2005/3/2 22:45 最後登入時間
: 2006/9/14 18:08
Group:
註冊會員
Level : 2 HP : 0 / 49 MP : 6 / 2833 EXP : 97
|
以下是I2C的程式範例 ==================================== #include <p18f452.h> #include <delays.h>
#define Write 0x00 #define Read 0x01 #define Device1 0x20
void F_Initial(void); void F_I2C_START(void); unsigned char F_I2C_WAIT(void); unsigned char F_I2C_Send_Address(unsigned char,unsigned char); void F_I2C_Send_Data(unsigned char); void F_I2C_STOP(void); unsigned char F_I2C_Read_Data(void);
void main(void) { unsigned char command=Write,UC_I2C_Data=0; F_Initial(); while(1) { switch (command) { case Write: F_I2C_START(); if (F_I2C_Send_Address(Device1,command)) F_I2C_Send_Data(UC_I2C_Data++); F_I2C_STOP(); Delay10KTCYx(20); command=Read; break; case Read: F_I2C_START(); if (F_I2C_Send_Address(Device1,command)) LATD = F_I2C_Read_Data(); F_I2C_STOP(); Delay10KTCYx(20); command=Write; break; default: break; } } }
void F_Initial(void) { TRISD = 0; LATD = 0; TRISCbits.TRISC3 = 0; TRISCbits.TRISC4 = 0; SSPSTATbits.SMP = 1; SSPSTATbits.CKE = 0; SSPCON1 = 0x38; SSPADD = 0x30; }
void F_I2C_START(void) { SSPCON2bits.SEN = 1; while(!F_I2C_WAIT()); }
unsigned char F_I2C_WAIT(void) { if ( PIR1bits.SSPIF ) { PIR1bits.SSPIF = 0; return (1); } else return (0); }
unsigned char F_I2C_Send_Address(unsigned char UC_Address,unsigned char UC_RW) { SSPBUF = ((UC_Address & 0xFE) | UC_RW); while(!F_I2C_WAIT()); if ( SSPCON2bits.ACKSTAT ) return (0); else return (1); }
void F_I2C_Send_Data(unsigned char UC_Data) { SSPBUF = UC_Data; while(!F_I2C_WAIT()); }
void F_I2C_STOP(void) { SSPCON2bits.PEN = 1; while(!F_I2C_WAIT()); }
unsigned char F_I2C_Read_Data(void) { unsigned char UC_Temp=0; SSPCON2bits.RCEN = 1; while(!F_I2C_WAIT()); UC_Temp = SSPBUF; SSPCON2bits.ACKDT = 1; SSPCON2bits.ACKEN = 1; while(!F_I2C_WAIT()); return ( UC_Temp ); } ==================================== 各位大大~ 以上程式是課本的範例,小弟在跑的時候出現了以下錯誤 ICD0161: Verify failed (MemType = Program, Address = 0x0, Expected Val = 0xEF2A, Val Read = 0x0) ICD0275: Programming failed.
我嘗試改一些宣告,雖然compiler過了還是出現上述的錯誤 請問~究竟是那裡出錯呢? 敬請賜教!!感激不盡~~~
註:在下小弟我使用MPLAB IDE V7.10與ICD2與APP001
發表於: 2005/8/10 21:51
|
|
You can view topic.
你 不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.