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


Browsing this Thread:   1 Anonymous Users




(1) 2 3 4 »


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


查看用戶資訊
打錯了,
PORTD=0x01 改成 PORTD=0x08

發表於: 2009/10/9 15:09
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


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


查看用戶資訊
我做了一些測試,全部都被Eigen料中,實在佩服!
1. 因為我用的是Lower four bits,所以我把
PORTD=0x01 改成 PORTD=0x80,一執行就當了,改成其他數值,只要RD3不是1都沒事。
2. 在BusyXLCD() 加入TRIS_DATA_PORT |= 0x0f; 這個問題便消失了。

發表於: 2009/10/9 15:02
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Reset 幾次後程式會被改掉
#34
資深會員
資深會員


查看用戶資訊
我仔細看過 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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


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


查看用戶資訊
1. 我有使用LCD R/W。
2. 以之前的狀況來看,在加上那一行指令之前,如果一樣多按幾次reset,不管有沒有接LCD,都會當掉,猜想可能有LCD時,等不到LCD ready所以會當,沒有LCD時接腳FLOATING一樣會當掉。

發表於: 2009/10/8 18:30
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Reset 幾次後程式會被改掉
#32
版主
版主


查看用戶資訊
LCD 拔掉後,RW 腳變 Floating 這時誰知道她是Hi or Low ? 所以BusyXLCD( ) 的 Return 值就有可能是 0,所以就莫名奇妙的就 Pass while (BusyXLCD()); 的檢查了。
問你一下,你有使用 LCD R/W 的腳位嗎?

發表於: 2009/10/8 9:30
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Reset 幾次後程式會被改掉
#31
資深會員
資深會員


查看用戶資訊
有些程式是照著datasheet寫,有些則是偷吃步

有好有壞,見人見智,不經一事,不長一智

多練習就會知道~~

(以前我寫過一個程式,一個硬體,七個版本,多個lcd ,少個 led ,多個開關,少個開關....

這種怪問題就自然發生過

發表於: 2009/10/7 21:26
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


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


查看用戶資訊
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Reset 幾次後程式會被改掉
#29
版主
版主


查看用戶資訊
LCD Module 在 Power On 後按規格要 Delay 15mS 後才可以下 command,而且每個 Command 都有不等的執行時間。

BusyXLCD( ) 會去 check LCD 的 R/W 腳,有時後為減少接腳數會不接 R/W 訊號,而改用Delay 的方式。所以請檢查一下你板子上是否又接 R/W。

發表於: 2009/10/7 13:28
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Reset 幾次後程式會被改掉
#28
資深會員
資深會員


查看用戶資訊
您的這個程式雖然是官方的,但是蠻怪的。因為您的LCD是用4BITS去控制的,而您已經將它設為Output,但是BusyXLCD()這個函式在Read這幾支腳時,卻沒有將它設為Intput。
所以這四支腳一直處於Output的情況,那麼要怎麼讀取Busy的值呢?


另外,您的這個程式好像是舊版的,因為我跟我的不一樣^^"

參照:

Zenith 寫道:
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 13:27
我相信解決問題的方法不只一種,所以我在回答同好的問題時或者提出與主題不同的方案,
請不要以此做為攻擊的目標,畢竟我也只是想和大家討論如何解決問題而已…
解決問題最重要,.....
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


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


查看用戶資訊
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
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... ]

教育訓練中心

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