• 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: EX12_1_UART
#3
新會員
新會員


查看用戶資訊
請問終端機要如何設定阿?

發表於: 2009/7/31 14:03
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


EX12_1_UART
#2
初級會員
初級會員


查看用戶資訊
我的終端機可以接收到mcu的資料
但是在終端機上打字都沒顯示且會停格
我檢查U1STA的UR1DA始終是0

應該是電腦沒送訊號?
請問該怎麼辦?

----------------------------
非常感動..我找到錯誤了
終端機沒設定好

發表於: 2009/5/28 19:50
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


EX12_1_UART
#1
初級會員
初級會員


查看用戶資訊
在試用曾百由老師的EX12_1_UART
我開超級終端機,執行的時候電腦可以收到Exercise 12 - UART
電腦傳值的時候電腦會稍微停頓,而且沒反應。
是我的哪邊設定有問題?


超級終端機設定
每秒傳輸位元 9600
資料位元 8
同位檢查 無
停止位元 1
流量控制 硬體

程式是曾百由老師的EX12_1_UART


//-----------------------題外話---------
//最近是我家網路怪怪的還是網站有問題
//有時候會突然開不起來,10分鐘又好了。
//但是連線速度變很慢。
//---------------------------

// ***********************************************************************
// File : EX12_1_UART.C
// Purpose : 練習如何叫 Microchip C30 提供的 UART 函式庫
//
// 使用的函式 :
// OpenUART1( )
// ConfigIntUART1( )
// BusyUART1( )
// DataRdyUART1( )
// ReadUART1( )
// WriteUART1( )
// getsUART1( )
// putsUART1( )
// CloseUART1( )
//
// 動作 :
// Exercise 12 - ADC
// VR2:YYY
//
// 將 UART1 規劃成接收中斷,所以當使用者每次按電腦鍵盤時
// 進行類比訊號轉換,並將轉換結果輸出至UART
//
//
// ***********************************************************************

#define __dsPIC30F4011__

#include <p30F4011.h>
#include <uart.h> // 將UART函式的原型宣告檔案含入
#include <timer.h> // 將Timer函式的原型宣告檔案含入
#include <adc10.h> // 將adc10函式的原型宣告檔案含入

#define FCY 7372800 * 2 // 因為使用頻率為將外部 7.3728 MHz * 8 的模式 , 每一指令週期需 4 個 clock
// 所以 FCY = (7.3728 * 8 / 4 ) MHz = 7372800* 2

_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

const char My_String1[]="\r\nExercise 12 - UART\r\n" ; // 宣告字串於 Program Memory (因為 const 宣告)

void Init_ADC(void) ;
void Init_UART(void) ;
void Show_ADC(void) ;
void sitoa(unsigned char, unsigned char *TXdata ) ;

void _ISR _U1RXInterrupt(void) // UART1接收資料中斷副程式
{

unsigned char dummy;

dummy = ReadUART1() ; // 將UART讀取資料暫存器的內容讀出

Show_ADC();

IFS0bits.U1RXIF = 0 ;

}

int main( void )
{

Init_ADC( ) ; // 將ADC進行初始化設定

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

putsUART1( (unsigned int *) My_String1 ) ; // 將存在 Program Memory 的字串輸出

while(1) ;

CloseUART1();
}

/***********************************************/
// Subroutine to configure the A/D module

void Init_ADC(void)
{

unsigned int Channel, PinConfig, Scanselect, Adcon3_reg, Adcon2_reg, Adcon1_reg;

ADCON1bits.ADON = 0; /* turn off ADC */

PinConfig = ENABLE_AN0_ANA; // Select port pins as analog inputs ADPCFG<15:0>

Adcon1_reg = ADC_MODULE_ON & // Turn on A/D module (ADON)
ADC_IDLE_STOP & // ADC turned off during idle (ADSIDL)
ADC_FORMAT_INTG & // Output in integer format (FORM)
ADC_CLK_MANUAL & // Conversion trigger manually (SSRC)
ADC_SAMPLE_INDIVIDUAL & // Sample channels individually (SIMSAM)
ADC_AUTO_SAMPLING_OFF; // Sample trigger manually (ASAM)

Adcon2_reg = ADC_VREF_AVDD_AVSS & // Voltage reference : +AVdd, -AVss (VCFG)
ADC_SCAN_OFF & // Scan off (CSCNA)
ADC_ALT_BUF_OFF & // Use fixed buffer (BUFM)
ADC_ALT_INPUT_OFF & // Does not alternate between MUX A & MUX B (ALTS)
ADC_CONVERT_CH0 & // Convert only channel 0 (CHPS)
ADC_SAMPLES_PER_INT_1; // 1 sample between interrupt (SMPI)

Adcon3_reg = ADC_SAMPLE_TIME_10 & // Auto-Sample time (SAMC)
ADC_CONV_CLK_SYSTEM & // Use system clock (ADRC)
ADC_CONV_CLK_4Tcy; // Conversion clock = 4 Tcy (ADCS)
// ADCS = 2*(154ns)/(1/Fcy)-1 = 3.5416

Scanselect = SCAN_NONE; // ADC scan no channel (ADCSSL)

OpenADC10(Adcon1_reg, Adcon2_reg, Adcon3_reg, PinConfig, Scanselect);

Channel = ADC_CH0_POS_SAMPLEA_AN0 & // CH0 Pos. : AN0, Neg. : Nominal Vref- Defined in ADCON2
ADC_CH0_NEG_SAMPLEA_NVREF ; // (ADCHS)
SetChanADC10(Channel);

ConfigIntADC10(ADC_INT_DISABLE); // Disable ADC interrupt

}

/***********************************************/
// 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;
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(U1MODEvalue, U1STAvalue, baudvalue);

return;

}

/***********************************************/
// Subroutine to show Time on UART

void Show_ADC(void)
{

unsigned char dummy ;
unsigned int ADCValue;
unsigned char TXdata[4];
ADCON1bits.SAMP = 1; // start sampling ...

for ( dummy = 0 ; dummy < 200 ; dummy ++ );

ConvertADC10();
while (BusyADC10()); // conversion done?
ADCValue = (ADCBUF0 >> 2); // get ADC value

sitoa(ADCValue, (unsigned char *)TXdata);

putsUART1( (unsigned int *) "VR2 : ");
putsUART1( (unsigned int *) TXdata ) ;
putsUART1( (unsigned int *) "\r\n" );

}

//***********************************************
// Put a unsigned byte in decimal format
// to UART Module

void sitoa( unsigned char The_Number, unsigned char *buff)
{

unsigned char Temp_Char_100, Temp_Char_10, Temp_Char ;
unsigned char *temp = (unsigned char *)buff ;

Temp_Char_100 = The_Number /100 ; //取百位數的數字
temp[0] = Temp_Char_100 + '0' ; //取百位數的數字
Temp_Char_10 = (The_Number - Temp_Char_100*100) /10 ; //取十位數的數字
temp[1] = Temp_Char_10 + '0' ; //取十位數的數字
Temp_Char = The_Number - ( Temp_Char_100*100 + Temp_Char_10 * 10 ) ; //取個位數的數字
temp[2] = Temp_Char + '0' ; //取個位數的數字
temp[3] = 0 ;
}

發表於: 2009/5/28 10:51

Edited by z2490438 on 2009年05月28日 11:33:28
Edited by z2490438 on 2009年05月28日 15:12:00
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... ]

教育訓練中心

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