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

論壇索引


Board index » All Posts (jghn)




請問 C30 的延遲時間怎麼寫
#11
新會員
新會員


請問 C30 的延遲時間怎麼寫

發表於: 2008/9/1 21:19
頂部


超級終端機 沒反應~~
#12
新會員
新會員


動作 :將 UART1 (RS232) 規劃成接收中斷,所以當使用者每次按電腦鍵盤時,進行類比訊號轉換,並將轉換結果輸出至UART

鮑率9600

問題:與超級終端機連線時只會出現"Exercise 12 - 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 ;
}

發表於: 2008/8/5 13:14
頂部


用開關控制矩陣在LCD顯示
#13
新會員
新會員


動作說明: 先在矩陣中存入要的數字或字母 , 然後按開關在LCD會依序出現 2 4 6 8 , 但打出來卻亂碼在跳 ,不知哪寫錯了,請各位大大指教~




putcLCD(z); <=g是這句語法錯誤嗎? 因為z為變數

////////////////////////////////////////

#include <p30F4011.h>
#include "C30EVM_LCD.h"
int main( void )
{
LATE=0xffff;
ADPCFG=0Xffff;
TRISE=0xffc0;
OpenLCD( );
unsigned char array[2][4]={{'1','3','5','7'},{'2','4','6','8'}};
int y=0;
unsigned char z;
while(1) {
if( PORTEbits.RE8==0 )
{ y=y+1;
z=array[2][y];
setcurLCD(0,1);
putcLCD(z);
}

while(PORTEbits.RE8==0);
}
}

發表於: 2008/8/4 21:53
頂部


Re: 用開關控制矩陣在LCD顯示之問題
#14
新會員
新會員


還是亂碼的說~

putcLCD(z); <=g是這句語法錯誤嗎? 因為z為變數

////////////////////////////////////////

#include <p30F4011.h>
#include "C30EVM_LCD.h"
int main( void )
{
LATE=0xffff;
ADPCFG=0Xffff;
TRISE=0xffc0;
OpenLCD( );
unsigned char array[2][4]={{'1','3','5','7'},{'2','4','6','8'}};
int y=0;
unsigned char z;
while(1) {
if( PORTEbits.RE8==0 )
{ y=y+1;
z=array[2][y];
setcurLCD(0,1);
putcLCD(z);
}

while(PORTEbits.RE8==0);
}
}

發表於: 2008/8/4 21:42
頂部


PIC30F4011 之USB傳輸
#15
新會員
新會員


請問C30 可以透過 1.RS-232轉USB 傳資料到電腦嗎?
2.透過PIN腳轉USB 傳送資料
3.或自製面板 USB-USB

發表於: 2008/8/4 12:39
頂部


用開關控制矩陣在LCD顯示之問題
#16
新會員
新會員


動作說明: 先在矩陣中存入要的數字 , 然後按開關在LCD會依序出現 2 4 6 8 , 但打出來卻亂碼在跳 ,不知哪寫錯了,請各位大大指教~







/////////////////////////////////////////////

#include <p30F4011.h>
#include "C30EVM_LCD.h"
int main( void )
{
LATE=0xffff;
ADPCFG=0Xffff;
TRISE=0xffc0;
OpenLCD( );
int array[2][4]={{1,3,5,7},{2,4,6,8}};
int a=4;
int y=0;
int z;
while(1) {
if( PORTEbits.RE8==0 )
{ y=y+1;
z=array[2][y];
setcurLCD(0,1);
putrsLCD(z);





while(PORTEbits.RE8==0);
}

}
}

發表於: 2008/8/3 23:44
頂部


程式重置撰寫問題
#17
新會員
新會員


各位大大,請問在程式中想要寫一個語法按下SW1後,可以跳到前面程式未執行前的狀態,即是從頭開始動作,該如何撰寫?

如下所示:

#include <p30F4011.h>
#include "C30EVM_LCD.h"
int main( void )
{
LATE=0xffff;
ADPCFG=0Xffff;
TRISE=0xffc0;
OpenLCD( );
int a=2;
while(1) {
if( (PORTEbits.RE8==0) && (a%2==0) )
{ a=a+1;
setcurLCD(0,1);
putrsLCD("1");
while(PORTEbits.RE8==0);
}
else if( (PORTEbits.RE8==0) && (a%2==1) )
{ a=a+1;
setcurLCD(0,1);
putrsLCD("A");
while(PORTEbits.RE8==0);
}

if(PORTBbits.RB8==0)
{
if(PORTBbits.RB8==0)
goto Line ???????;
}
}
}

發表於: 2008/7/31 17:28
頂部


請問各位大大有C30的範例跟書、講義可供新手參考嗎?
#18
新會員
新會員


請問有C30的範例跟書、講義可供新手參考嗎?

另求C18的電路圖 謝謝

發表於: 2008/7/31 14:47
頂部


各位大大 請教有關LCD 輸入密碼鎖
#19
新會員
新會員


密碼是1234
有按鈕 SW1~4
輸入密碼 在LCD 上會顯示 1=>12=>123

請問這種位移 用C語言 要怎麼寫~



我只會從左邊寫到右邊
不適用位移 適用指定座標寫~

發表於: 2008/7/30 17:10
頂部



« 1 (2)



:::

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

教育訓練中心

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