:::

論壇索引


Board index » All Posts (Zenith)




Re: Reset 幾次後程式會被改掉
#91
高級會員
高級會員


1. biko說的沒錯,因為程式在執行的時候還蠻正常的,所以並沒有去細看你所提到的問題。以此類推,底下這段官方版的程式也沒有在檢查LCD是不是真的Busy。
#include <p18cxxx.h>
#include "xlcd.h"

/********************************************************************
* Function Name: putsXLCD
* Return Value: void
* Parameters: buffer: pointer to string
* Description: This routine writes a string of bytes to the
* Hitachi HD44780 LCD controller. The user
* must check to see if the LCD controller is
* busy before calling this routine. The data
* is written to the character generator RAM or
* the display data RAM depending on what the
* previous SetxxRamAddr routine was called.
********************************************************************/
void putsXLCD(char *buffer)
{
while(*buffer) // Write data to LCD up to null
{
while(BusyXLCD()); // Wait while LCD is busy
WriteDataXLCD(*buffer); // Write character to LCD
buffer++; // Increment buffer
}
return;
}

也難怪我把LCD拔掉,LED顯示程式仍在動。

2. LCD 的 Busy 按照LCD手冊記載,不論是4或8 bit bus,都是檢查DB7,所以R/W、 RS 和 E我都有接。

#define RW_PIN PORTDbits.RD6 /* PORT for RW */
#define TRIS_RW DDRDbits.RD6 /* TRIS for RW */
#define RS_PIN PORTDbits.RD5 /* PORT for RS */
#define TRIS_RS DDRDbits.RD5 /* TRIS for RS */
#define E_PIN PORTDbits.RD7 /* PORT for E */
#define TRIS_E DDRDbits.RD7 /* TRIS for E */

發表於: 2009/10/7 15:20
頂部


Re: Reset 幾次後程式會被改掉
#92
高級會員
高級會員


1. BusyXLCD()內容如下,這是Microchip原有的程式,我沒有改它。
#include <p18cxxx.h>
#include "xlcd.h"

/********************************************************************
* Function Name: BusyXLCD *
* Return Value: char: busy status of LCD controller *
* Parameters: void *
* Description: This routine reads the busy status of the *
* Hitachi HD44780 LCD controller. *
********************************************************************/
unsigned char BusyXLCD(void)
{
RW_PIN = 1; // Set the control bits for read
RS_PIN = 0;
DelayFor18TCY();
E_PIN = 1; // Clock in the command
DelayFor18TCY();
#ifdef BIT8 // 8-bit interface
if(DATA_PORT&0x80) // Read bit 7 (busy bit)
{ // If high
E_PIN = 0; // Reset clock line
RW_PIN = 0; // Reset control line
return 1; // Return TRUE
}
else // Bit 7 low
{
E_PIN = 0; // Reset clock line
RW_PIN = 0; // Reset control line
return 0; // Return FALSE
}
#else // 4-bit interface
#ifdef UPPER // Upper nibble interface
if(DATA_PORT&0x80)
#else // Lower nibble interface
if(DATA_PORT&0x08)
#endif
{
E_PIN = 0; // Reset clock line
DelayFor18TCY();
E_PIN = 1; // Clock out other nibble
DelayFor18TCY();
E_PIN = 0;
RW_PIN = 0; // Reset control line
return 1; // Return TRUE
}
else // Busy bit is low
{
E_PIN = 0; // Reset clock line
DelayFor18TCY();
E_PIN = 1; // Clock out other nibble
DelayFor18TCY();
E_PIN = 0;
RW_PIN = 0; // Reset control line
return 0; // Return FALSE
}
#endif
}

2. RD0~RD3接到LCD的DB4~DB7

發表於: 2009/10/7 12:28
頂部


Re: Reset 幾次後程式會被改掉
#93
高級會員
高級會員


非常感謝Eigen的指點,我在ResetLCD()前加一行看LED狀態的程式,沒想到問題消失了,應該是如Eigen所言,LCD尚未Ready,加一行程式剛好等候LCD完成Reset,感謝各位先進提供的意見,真的學到不少知識。
TRISB=0xff;
TRISD=0;
TRISB=0;
PORTB=0;
PORTD=0x01; <--增加此行
ResetLCD();
OpenXLCD(FOUR_BIT & LINES_5X7);

發表於: 2009/10/7 12:01
頂部


Re: Reset 幾次後程式會被改掉
#94
高級會員
高級會員


補充一下:
1. 當機時,RESET 按久一點沒有效。
2. RESET 電路是由Vdd接1K電阻串聯0.47uf電容接地,按鍵開關與電容並聯,電阻與電容連接處接至MCLR。

發表於: 2009/10/6 18:18
頂部


Re: Reset 幾次後程式會被改掉
#95
高級會員
高級會員


1. 我將LCD接至PORTD,PORTD的每一個BIT都有接電阻加LED,所以可看到訊號傳遞的狀態,將LCD拔掉,LED的變化仍舊正常,但是RESET幾次仍會出問題,似乎與LCM無關。
2. 底下是我的主程式部份,主要是利用I2C介面從MCP9800取得溫度然後顯示在20*4 LCD上,不知道有沒有可改善之處。

#include <p18cxxx.h>
#include <delays.h>
#include "xlcd.h"
#include "i2c.h"

#pragma udata
char Line1[18]="Temperature:";
char Line2[18]="----------------";
void locate(char RowNo, char ColNo);
//Locate LCD cursor
void cls(void);
//Clear LCD screen
void ResetLCD(void);
//LCD software reset
int ftoa (float x, char *str, char prec, char format);
//Transfer float to string for LCD
int abs(int data1, int data2);
//Get positive data

#pragma code
void main(void)
{
int i,j;
unsigned char temp[2];
int Temperature, TempCal1, TempCal2;
float RealTemp;
char resultString[20];
int StrLength;

TRISB=0xff;
TRISD=0;
TRISB=0;
PORTB=0;
ResetLCD();
OpenXLCD(FOUR_BIT & LINES_5X7);

cls();
locate(1,1);
putsXLCD(Line1);
WriteCmdXLCD(CURSOR_OFF&BLINK_OFF);
// Display OFF/Blink OFF

//*** Initialize I2C port
SSPADD=0x19;
OpenI2C(MASTER, SLEW_ON);
EEByteWrite(0x90,0x01,0x60);
//Write configuration register to set resolution at 12 bits
while(1)
{
EESequentialRead( 0x90, 0, temp, 2 );
TempCal1=temp[0];
TempCal2=temp[1];
TempCal1=TempCal1<<4;
Temperature=(TempCal2>>4)+TempCal1;
RealTemp=(float)Temperature*0.0625;
StrLength= ftoa(RealTemp, resultString, 2, 'f');
locate(2,1);
while(BusyXLCD());
DelayPORXLCD();
putsXLCD(resultString);
for(i=0;i<50;i++) DelayPORXLCD();
}
}

發表於: 2009/10/6 18:08
頂部


Re: Reset 幾次後程式會被改掉
#96
高級會員
高級會員


1. 我的電源供應器的5V可以調到4.5V,當BOR設為4.5V時,在電壓降至4.5V時,CPU HALT,往上調到4.5XV時就RESET,看來動作相當正常。
2. 我在MCLR 原本就有加按鍵做 Reset ,一開始發現問題也是因為按了幾次RESET後就會當掉。
3. 所以整個狀況描述如下:
<1>. MCU正常運轉-->按RESET鍵幾下-->MCU HALT-->按RESET鍵也無效-->拔掉5V接頭 (似乎不需要將Vdd與Vss短路)-->接回5V接頭 --> 正常
<2>. MCU正常運轉-->拔掉110V插頭-->經過幾秒插回110V插頭-->MCU HALT-->按RESET鍵也無效-->拔掉5V接頭 -->接回5V接頭 --> 正常
<3>. MCU正常運轉-->拔掉5V接頭 -->接回5V接頭-->MCU正常運轉

發表於: 2009/10/6 14:04
頂部


Re: Reset 幾次後程式會被改掉
#97
高級會員
高級會員


我的電路是利用I2C介面接一個MCP9800擷取12位元的溫度數據,並將其顯示在LCD上,LCD以四位元的方式接到PORTD,所有的控制腳也在PORTD,整個電路只有從一個5V Switching power supply 供電,所以並沒有IO外接其他電源的問題, 我會再試試看版主建議的方法。

另外今天還發現一個怪現象,如果關掉電源是以拔掉110V插頭的方式(即電源供應器的5V接頭仍接在電路板上),隔幾秒鐘再插回110V插頭,也會發生一樣的當機問題,此時只要拔掉5V connector再接回去就會回覆正常,如果關掉電源是以拔掉5V connector的方式則一切正常。

發表於: 2009/10/6 12:29
頂部


Re: Reset 幾次後程式會被改掉
#98
高級會員
高級會員


我把BOR Reset 電壓設定為 4.2 V和4.5V都沒有效果。
不過想請教一下,BOR不是用來偵測Vdd異常的嗎?依照DATASHEET的方塊圖所示,MCLR似乎自成獨立的外部觸發訊號,不知道這個觀念對不對?

發表於: 2009/10/5 17:35
頂部


Re: Reset 幾次後程式會被改掉
#99
高級會員
高級會員


1. 將linker file 中 c018i.o 改為 c018iz.o 結果仍然一樣。
2. 請問Eigen指的是"Brown out detect"選項嗎? 我試過全部四個選項也都無效。
3. 由於有些程式是不會發生這個問題的,這樣還有可能是reset 電路不良所造成的嗎?

發表於: 2009/10/5 16:19
頂部


Re: Reset 幾次後程式會被改掉
高級會員
高級會員


測試結果如下:
1. 以ICD-2讀回 PIC 內部的程式碼跟程式做比較(用Verify選項),發現程式碼並未改變。
2.以Eigen建議的方式,將 vcc gnd 短路之後,再試結果是可以的。我的程式並沒有 flash 讀寫的程序,請問要加上哪些指令來模擬這個短路放電的過程或避免程式死當?

發表於: 2009/10/5 15:04
頂部



« 1 ... 7 8 9 (10) 11 »



:::

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... ]

教育訓練中心

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