Re: Reset 幾次後程式會被改掉
|
||||
---|---|---|---|---|
高級會員
![]() ![]() ![]() |
打錯了,
PORTD=0x01 改成 PORTD=0x08
發表於: 2009/10/9 15:09
|
|||
|
Re: Reset 幾次後程式會被改掉
|
||||
---|---|---|---|---|
資深會員
![]() ![]() ![]() |
我仔細看過 busyXLCD 的內容,程序上是有問題的
我也知道為什麼 PORTD=0x01; <--增加此行 你的程式就會常了 <--------------------------------------------------------> busyXLCD 在做 busy 檢查時,沒有切換 busy pin 為 input ,而是維持 output 因此當你下完最後一個指令為 b'1xxx'時, busyXLCD 會一直看到 1 而你下 PORTD=0x01; 這個指令,則會將 busy pin 的 output 初成 0,所以busyXLCD 檢查為 0 換言之,這個 busyXLCD 基本上是沒有用處的。 <--------------------------------------------------------> 那為什麼你的程式一開始會正常, 因為你一開始下的命令 bit7 都是 0 ,一般寫入的文字都是在 0x80 之前 (你可以試著顯示 0x80 之後的字,你的程序應該不用 reset 就會當在那了) 所以資料寫入在 bit7 都會是 0 因此 busyXLCD 看到的都是 0 一reset ,port 預設是 input ,lcd 常態性寫入,可能會是 busy (high) 所以reset 之後,改成 output ,卻沒改狀態,就會變成 high 然後 busyXLCD 檢查就掛了
發表於: 2009/10/9 8:59
|
|||
|
Re: Reset 幾次後程式會被改掉
|
||||
---|---|---|---|---|
高級會員
![]() ![]() ![]() |
1. 我有使用LCD R/W。
2. 以之前的狀況來看,在加上那一行指令之前,如果一樣多按幾次reset,不管有沒有接LCD,都會當掉,猜想可能有LCD時,等不到LCD ready所以會當,沒有LCD時接腳FLOATING一樣會當掉。
發表於: 2009/10/8 18:30
|
|||
|
Re: Reset 幾次後程式會被改掉
|
||||
---|---|---|---|---|
版主
![]() ![]() ![]() |
LCD 拔掉後,RW 腳變 Floating 這時誰知道她是Hi or Low ? 所以BusyXLCD( ) 的 Return 值就有可能是 0,所以就莫名奇妙的就 Pass while (BusyXLCD()); 的檢查了。
問你一下,你有使用 LCD R/W 的腳位嗎?
發表於: 2009/10/8 9:30
|
|||
|
Re: Reset 幾次後程式會被改掉
|
||||
---|---|---|---|---|
資深會員
![]() ![]() ![]() |
有些程式是照著datasheet寫,有些則是偷吃步
有好有壞,見人見智,不經一事,不長一智 多練習就會知道~~ (以前我寫過一個程式,一個硬體,七個版本,多個lcd ,少個 led ,多個開關,少個開關.... 這種怪問題就自然發生過
發表於: 2009/10/7 21:26
|
|||
|
Re: Reset 幾次後程式會被改掉
|
||||
---|---|---|---|---|
高級會員
![]() ![]() ![]() |
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 幾次後程式會被改掉
|
||||
---|---|---|---|---|
版主
![]() ![]() ![]() |
LCD Module 在 Power On 後按規格要 Delay 15mS 後才可以下 command,而且每個 Command 都有不等的執行時間。
BusyXLCD( ) 會去 check LCD 的 R/W 腳,有時後為減少接腳數會不接 R/W 訊號,而改用Delay 的方式。所以請檢查一下你板子上是否又接 R/W。
發表於: 2009/10/7 13:28
|
|||
|
Re: Reset 幾次後程式會被改掉
|
||||
---|---|---|---|---|
資深會員
![]() ![]() ![]() |
您的這個程式雖然是官方的,但是蠻怪的。因為您的LCD是用4BITS去控制的,而您已經將它設為Output,但是BusyXLCD()這個函式在Read這幾支腳時,卻沒有將它設為Intput。
所以這四支腳一直處於Output的情況,那麼要怎麼讀取Busy的值呢? 另外,您的這個程式好像是舊版的,因為我跟我的不一樣^^" 參照:
發表於: 2009/10/7 13:27
|
|||
我相信解決問題的方法不只一種,所以我在回答同好的問題時或者提出與主題不同的方案,
請不要以此做為攻擊的目標,畢竟我也只是想和大家討論如何解決問題而已… 解決問題最重要,..... |
||||
|
Re: Reset 幾次後程式會被改掉
|
||||
---|---|---|---|---|
高級會員
![]() ![]() ![]() |
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
|
|||
|