• 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: UART範例程式問題
#8
版主
版主


查看用戶資訊
10 是由兩個 ASCII Code 所組成的,其值為 0x31 及 0x30 ,而 Rec_buffer卻是只有一個byte,所以不可以這樣比的。
你必須先將 Rec_Buffer 先存道一個陣列裏,直到收到結束位元組後在一次做比較的。

發表於: 2008/10/24 15:52
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: UART範例程式問題
#7
新會員
新會員


查看用戶資訊
想再請教一下板主,如果我現在動作是傳1這個單一字元進來給PIC接收,讓我的LED1亮,我判別式是這樣寫
if(Rec_Buffer==0x31)
{
LED1 = 0;
}
動作沒問題,那如果我現在是要傳10這字串的話,那我判別式是這樣寫嗎?
if(Rec_Buffer==0x31&&030)
{
LED1 = 0;
}
然後我原本讀取Rec_Buffer是這樣寫
Rec_Buffer = ReadUART1( );
那要改成字串的話是要改成這樣嗎?
Rec_Buffer = getsUART1( );
不好意思一直麻煩版主!!!

發表於: 2008/10/23 21:09
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: UART範例程式問題
#6
版主
版主


查看用戶資訊
f (Rec_Count>=3)
{
setcurLCD(0,1) ; // 一定要顯示嗎?
Rec_Count=0; //錯在這裡

因為 Rec_Count 大於三時你又把它清為零所遠無法超過 4 當然就不會有超過 100 得計數,建議再加入一組count 來區別一下。

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


Re: UART範例程式問題
#5
新會員
新會員


查看用戶資訊
想在請問一下板主,因為我是用APP020學習板,例如我要從LabVIEW傳個100的字串给PIC,然後要讓APP020的LED1亮,再傳個101的字串就讓LED1滅,想請問版主我要如何去抓這些字串,我是想利用你的程式去改,我執行結果就是當我LabVIEW不管傳什麼值都只會讓LED1亮,我抓取字串程式如下,其他程式都參照範例程式

while (1)
{
while ( !Rec_Flag) ;

Rec_Flag=0;

putcLCD(Rec_Buffer);
Rec_Count++;
if (Rec_Count>=3)
{
setcurLCD(0,1) ;
Rec_Count=0;
}
if(Rec_Buffer==100);
{
LED1 = 0;
}
if(Rec_Buffer==101);
{
LED1 = 1;
}
}
}

發表於: 2008/10/20 20:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: UART範例程式問題
#4
版主
版主


查看用戶資訊
這就是接收電腦傳來的字,程式採中斷方式接收並將將收到的可顯示的 ASCII Code 送給 LCD 的第二行顯示。

putcLCD(Rec_Buffer); //呼叫 LCD 顯示函數,顯示接收到的字元
Rec_Count++;
if (Rec_Count>=16) //LCD 一行顯示16個字
{
setcurLCD(0,1) ; //Course 設再第二行, 第一個位置
Rec_Count=0;

發表於: 2008/10/17 8:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: UART範例程式問題
#3
新會員
新會員


查看用戶資訊
感謝版主的熱心回答,想在請教一下板主if (Rec_Count>=16)的Rec_Count是代表什麼意思?還有就是我現在只要接受到電腦傳來的字,那就只要

putcLCD(Rec_Buffer);
Rec_Count++;
if (Rec_Count>=16)
{
setcurLCD(0,1) ;
Rec_Count=0;
}
就可以了嗎?也麻煩可以解釋一下這段程式的動作嗎?謝謝!!!

發表於: 2008/10/16 19:32
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: UART範例程式問題
#2
版主
版主


查看用戶資訊
這程式是我寫的,說明如下 :

SRbits.IPL=4; 設定 CPU 的中斷優先權為 4 ,而 UART 的接收中斷優先權設為 6 。在這裡設的ConfigIntUART1(UART_RX_INT_EN & UART_RX_INT_PR6 &
UART_TX_INT_DIS & UART_TX_INT_PR2);

if (Rec_Buffer==0x0d) 判斷街道的字元為按鍵的 Enter key 其值為 0x0D,如果收到 0x0D 則表示收到結速控制字元。

發表於: 2008/10/16 9:20
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


UART範例程式問題
#1
新會員
新會員


查看用戶資訊
想請教各位前輩,小弟有在下載中心下載課程裡的一個關於UART的範例程式,範例程式如下,想請教關於下列兩行紅色部份是表示什麼,還有小弟是個新手想請教一下Rec_Buffer是代表讀取由電腦傳來的值嗎?謝謝!!!
/************************************************************/
/*                                                             */
/*                       EUART Lab 1                            */
/*                                                             */
/* Note:                                                    */
/*        DSW1 – SW1 & SW2 are ON position for the ICD2         */
/*             programming & using the PGC, PGD for Debug    */
/*        DSW2 – SW1 & SW2 are ON position for UART1 (Lab1)    */
/*             SW3 & SW4 are OFF position for Dis UART2     */
/*        DSW3 – SW1 & SW2 are ON position for VR input        */
/*        DSW4 – All OFF position                                */
/************************************************************/
//
#include     <p30fxxxx.h>
#include     "C30EVM_LCD.h"            // 將LCD函式的原型宣告檔案含入 
#include     <uart.h>                // 將UART函式的原型宣告檔案含入 
#include    <Stdio.h>
#include     <math.h>

void    Test_UART(void);
void    Init_UART(void);

const 
char    UART_LCD1[]="* Test UART 1 * " ;
const 
char    UART_LCD2[]="Send a float out" ;
const 
char  UART_LCD3[]=" Received UART1 " ;
const 
char  UART_LCD4[]="                " ;
const 
char  UART_LCD5[]="Press 'Enter' ??" ;

float Sin_A;
char Rec_Buffer=0;
char Rec_Flag=0;
char Rec_Count=0;
#define PI 3.14159

       
_FOSC(CSW_FSCM_OFF XT_PLL8);   //    XT with 8xPLL oscillator, Failsafe clock off
       
_FWDT(WDT_OFF);                  //    Watchdog timer disabled
      
_FBORPOR(PBOR_OFF MCLR_EN);    //    Brown-out reset disabled, MCLR reset enabled
       
_FGS(CODE_PROT_OFF);             //    Code protect disabled

void _ISR _U1RXInterrupt(void)
{
    
Rec_Buffer ReadUART1( );      // Read data from Receiver FIFO
    
Rec_Flag 1;                      // Set the Received Flag
    
IFS0bits.U1RXIF ;            // Clear Interrupt Flag
}


int    mainvoid )
{
    [
color=CC0000]SRbits.IPL=4;[/color]

    
OpenLCD( ) ;                    // 使用 OpenLCD( )對 LCD 模組作初始化設定
    
Test_UART( );                    // UART 模組測試程式
}

void Test_UART(void )
{
    
unsigned char n;

    
Init_UART( ) ;                                        // 對 UART 模組作初始化設定

    
printf("x1b[2J");

    
setcurLCD(0,0) ;                                    // 使用 setcurLCD( ) 設定游標於 (0,0)
    
putrsLCDUART_LCD1 ) ;
    
setcurLCD(0,1) ;                                    // 使用 setcurLCD( ) 設定游標於 (0,1)
    
putrsLCDUART_LCD2 ) ;

    
printf("************************************************************rn");
    
printf("*    Microchip Workshop RTC Training         Exercise 1 :  *rn");
    
printf("*    Please send the folat value form SIN 0 ~ 180 deg      *rn");
    
printf("************************************************************rn");

    for    (
n=0;n<190;n+=10)
    {
        
Sin_A sinf((n*PI)/180);
        
printf("     SIN %3d deg = %fnr",n,Sin_A);
    }

    
setcurLCD(0,1) ;                                    // 使用 setcurLCD( ) 設定游標於 (0,1)
    
putrsLCDUART_LCD5 ) ;


        while (
1)
        {
            while ( !
Rec_Flag) ;

            
Rec_Flag=0;
            if ([
color=CC0000]Rec_Buffer==0x0d[/color])
                {
                    
setcurLCD(0,0) ;
                    
putrsLCDUART_LCD3 ) ;  
                    
setcurLCD(0,1) ;
                    
putrsLCDUART_LCD4 ) ; //Clear Line 2 of LCD
                    
setcurLCD(0,1) ;
                    
Rec_Count=0;
                }
            else
                {    
                    
putcLCD(Rec_Buffer);
                    
Rec_Count++; 
                    if (
Rec_Count>=16)
                    {
                        
setcurLCD(0,1) ;
                        
Rec_Count=0;
                    }
                }
        
        }
}

/***********************************************/
// Subroutine to initialize UART module

void    Init_UART(void)
{
    
/* Holds the value of baud register */
    
unsigned int baudvalue;
    
/* Holds the value of uart config reg */
    
unsigned int U1MODEvalue;
    
/* Holds the information regarding uart
    TX & RX interrupt modes */
    
unsigned int U1STAvalue;
    
/* Turn off UART1module */
    
CloseUART1();
    
/* Configure uart1 receive and transmit interrupt */
    
ConfigIntUART1(UART_RX_INT_EN UART_RX_INT_PR6 &
    
UART_TX_INT_DIS UART_TX_INT_PR2);
    
/* Setup the Buad Rate Generator */
    
baudvalue 95;            //UxBRG = ( (FCY/Desired Baud Rate)/16) – 1
                            //UxBRG = ( (7372800*2/9600)/16-1) = 95
    /* Configure UART1 module to transmit 8 bit data with one stopbit.
    Also Enable loopback mode */
    
U1MODEvalue UART_EN UART_IDLE_CON &
                
UART_DIS_WAKE UART_DIS_LOOPBACK &
                
UART_DIS_ABAUD UART_NO_PAR_8BIT &
                
UART_1STOPBIT UART_ALTRX_ALTTX;
    
U1STAvalue UART_INT_TX_BUF_EMPTY &
                
UART_TX_PIN_NORMAL &
                
UART_TX_ENABLE UART_INT_RX_CHAR &
                
UART_ADR_DETECT_DIS &
                
UART_RX_OVERRUN_CLEAR;
    
OpenUART1(U1MODEvalueU1STAvaluebaudvalue);

    return;

發表於: 2008/10/15 22:40

Edited by Ryang on 2008年10月16日 09:21:45
Edited by Ryang on 2008年10月16日 09:22:20
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... ]

教育訓練中心

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