• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: eeprom在timer中斷後做寫入、讀取
#4
中級會員
中級會員


查看用戶資訊
已經順利解決

1. 主程式忘了Initialize_I2C_Master();

2. 宣告要讀取的型態要一致,如

unsigned int rec[];

unsigned char *wrptr = rec;

沒注意到,要設一致才對

3. InitializeAD( ) 中不該用 ADC_INT_ON , 因未處理此中斷

只用到Timer中斷,雖然這不會影響讀值


4. OpenI2C(MASTER,SLEW_ON);

SSPADD = 20; <-- 沒設到... 搞笑 = ="


大致是醬吧...提供給大家一個小參考..大多是自已疏乎掉 ><

發表於: 2004/12/4 14:55
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: eeprom在timer中斷後做寫入、讀取
#3
中級會員
中級會員


查看用戶資訊
#pragma code isrhighcode = 0x0008
void isr_high_direct(void)
{
_asm //begin in-line assembly
goto isr_high //go to isr_high function
_endasm //end in-line assembly
}
#pragma code
//-----------------------------------------------------------------
#pragma interrupt isr_high
void isr_high(void)
{
if(PIR1bits.TMR2IF)
{
RCint();
PIR1bits.TMR2IF = 0 ; //Clear Timer2 interrupt Flag
}
}
#pragma code
//--------------------------------------------------------
void RCint()
{
CC++ ;
counter++ ;
if(counter/45==1) // 約3秒
{
ConvertADC(); // Convert A/D
while(BusyADC( )); // Waiting A/D until done
result = ReadADC();

PORTB=ADRESH; // Put A/D result on LEDs
count += 1;
rec[count] = result;
counter = 0 ;
}

if(CC/135==1)
{
EE_Page_Write(0xA0,0x00,0x01,10,wrptr);
EEPROM_ACK(0xA0);
EE_SEQU_Read(0xA0,0x00,0x01,10,rdptr);
CC = 0;
}
}

ps. wrptr是指標,指向rec陣列
rdptr是指向另一要讀取eeprom的陣列

//-------------------------------------------------------
void EE_Page_Write(unsigned char ctrl,unsigned char addr_h,unsigned char addr_l,unsigned char length,unsigned char *dptr)
{
IdleI2C();
StartI2C(); I2C_Done();

WriteI2C(ctrl); while(SSPCON2bits.ACKSTAT); I2C_Done();
WriteI2C(addr_h); while(SSPCON2bits.ACKSTAT); I2C_Done();

WriteI2C(addr_l);
while(SSPCON2bits.ACKSTAT);
I2C_Done();

while (length!=0) {
WriteI2C(*dptr); while(SSPCON2bits.ACKSTAT);
I2C_Done();
dptr++;
length--;
}
StopI2C(); I2C_Done();
}
//-----------------------------------------------------------
void I2C_Done(void)
{
while (!PIR1bits.SSPIF);
PIR1bits.SSPIF=0;
}
*************************************
主要在RCint這個中斷副程式上

程式流程是每兩秒我會做adc讀取,三次後我需把資料存入

eeprom,但程式就是停在EE_Page_Write上,在Write的副程

式裡停在I2C_Done(),Done的副程式停在while的判別式,

之前是單純在while(1)下跑,陣列都先預設好資料,可以存也

可以讀,I2C_Done那也沒問題,但移到timer的中斷副程式下

就完全動不了,很令人疑惑~~

對了,還有eeprom是外接的256k的eeprom

情況大致如此,謝謝各位

發表於: 2004/11/30 10:58
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: eeprom在timer中斷後做寫入、讀取
#2
中級會員
中級會員


查看用戶資訊
你寫入的eeprom是內部或外接的?
list 你的 write出來讓大家幫你抓bug吧!

發表於: 2004/11/30 9:08
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


eeprom在timer中斷後做寫入、讀取
#1
中級會員
中級會員


查看用戶資訊
各位先進您好

情況大概是我的pic在timer固定時間中斷後,做adc讀取

,之後放入陣列,同時我需寫入eeprom,但中斷點就停在

Write的函式,沒辦法往下跑。

之後我把adc部份拿掉,陣列直接設值,就在timer中斷後

直接寫入eeprom,情況也是一樣,沒法寫入,更別提之後要做

讀取動作。

不知各位有無遇此類情形,感謝您的指點迷津~~~

發表於: 2004/11/29 20:40
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







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.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------