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

論壇索引


Board index » All Posts (Issac)




APP023電路圖問題
#1
新會員
新會員


各位大大你們好
由於小弟最近想要製作一塊測試板
但是在劃protel的時候遇到ㄌ一些問題
pic18f8722這顆MCU有兩組USART
一組接到RS232使用的是RC6(TX)/RC7(RX)兩隻接腳
一組接到CAN使用的是RG0(TX)/RG2(RX)
但是我看了MCU的Datasheet發現
另一組USART應該是使用RG1(TX)和RG2(RX)
為什麼會這樣呢?

發表於: 2007/6/1 13:19
頂部


如何使用DemoBoard上的蜂鳴器???
#2
新會員
新會員


各位大大好
因為實作上需要使用到BUZZER
可是我不曉得該如何去驅動
不知道是否有相關的程式能夠參考
煩請解答
謝謝

發表於: 2007/5/30 22:50
頂部


Re: 詢問pic18f452 USART傳送問題
#3
新會員
新會員


感謝版主~我去研究參考看看~
有問題在上來發問
謝謝︿ ︿

發表於: 2007/3/21 18:54
頂部


Re: 詢問pic18f452 USART傳送問題
#4
新會員
新會員


感謝mechwe指正程式上的錯誤
可是我改正之後似乎仍然沒有反應
所以我簡述一下目前的狀況
引述Datasheet的內容
TXREG暫存器中的新數據(如果有的话)就會被裝入TSR。一但把TXREG 暫存器中的數據送入TSR暫存器(在一個TCY 周期内),TXREG暫存器就變為空,同時發送中斷旗標位TXIF(PIR1<4>)會置為1

但是我使用單步執行以及使用Watch觀看變數時發現我的TXREG的值會一直存在,似乎沒有傳送至TSR暫存器,才導致輸出沒有訊號
所以可能要朝這ㄍ方向研究才能知道問題出在哪裡
另外我使用的是APP001實驗版的擴充接腳,不曉得這是否對輸出有影響?

發表於: 2007/3/21 18:02
頂部


Re: 詢問pic18f452 USART傳送問題
#5
新會員
新會員


囧rz
還是不行~>"<

發表於: 2007/3/21 13:43
頂部


Re: 詢問pic18f452 USART傳送問題
#6
新會員
新會員


/* Include Header files */

#include <p18f452.h>
#include <timers.h>
#include <delays.h>
#include <usart.h>
#include <stdlib.h>
#include "P18F_LCD.h"

/* Declare the Function Prototype */
void InitializeUSART(void);
void InitializeINTs(void);
void InitializePORT(void);
void isr_high_direct(void);
void isr_high(void);

//*****************************************************
#pragma romdata My_romdata=0x1000
const rom char LCD_MSG1[]=" Power On";
const rom char LCD_MSG2[]=" Pumping Up";

#pragma romdata

//*****************************************************
#pragma udata access My_RAM_2
near unsigned char Rec_Data;
near unsigned char Data_Buffer[3];
near unsigned char Data_Temp[30];
#pragma udata

int i=0;
int j=0;

//***********************************************************
/* */
/* Main Program */
/* */
//***********************************************************

void main(void)
{
InitializePORT( );
OpenLCD( );
InitializeINTs( );
InitializeUSART( );
Rec_Data=0x00;
while(1)
{
TXSTAbits.TXEN=1;
while(TXSTAbits.TRMT=0);
putcUSART(0xA7);
while(TXSTAbits.TRMT=0);
putcUSART(0xA5);
while(TXSTAbits.TRMT=0);
putcUSART(0x5A);
}
}

//************************************************
//* #pragma Interrupt Declarations *
//************************************************
//************************************************
//* Function: isr_high_direct *
//* - Direct execution to the actual *
//* high-priority interrupt code. *
//************************************************
#pragma code isrhighcode = 0x0008

void isr_high_direct(void)
{
_asm //begin in-line assembly
goto isr_high //go to isr_high function
_endasm //end in-line assembly
}
#pragma code

//************************************************
//* Function: isr_high(void) *
//* High priority interrupt will *
//* - Received a serial data from RS-232 *
//* Save the received data to buffer Rec_Data*
//************************************************
#pragma interrupt isr_high

void isr_high(void)
{
// Rec_Data=ReadUSART(); // Get RS-232 data; clear RCIF
// Data_Buffer[i]=Rec_Data;
// Data_Temp[j]=Data_Buffer[i];
// if(Data_Temp[12]==0xA7 && Data_Temp[13]==0xA5 && Data_Temp[14]==0x5A )
// {
// while(TXSTAbits.TRMT=0);
// putcUSART(0xA7);
// while(TXSTAbits.TRMT=0);
// putcUSART(0xA5);
// while(TXSTAbits.TRMT=0);
// putcUSART(0x5A);
// }
// if (i<3)
// {
// i++;
// }
// else
// {
// i=0;
// }
// j++;
}
#pragma code

//************************************************
//* Function: Initialize Interrupts *
//* - Reset All Interrupr *
//* - Enable HIgh Priority Interrupt *
//* - Disable Low Priority Interrupt *
//************************************************
void InitializeINTs(void)
{
PIR1=0; //Clear all Interrupt setting & Flag
PIR2=0;
INTCON=0;
INTCON2=0;
INTCON3=0;
PIE1=0;
PIE2=0;

RCONbits.IPEN=1; //Enable priority interrupts
INTCONbits.GIEL=0; // Disable Low Priority Interrupt
INTCONbits.GIEH=1; // Enalbe high priority Interrupt
}
//************************************************
//* Function: Initialize USART *
//* - Initialize the RS-232 communication *
//* - Disable Interrupr for TxD *
//* - Enable Interrupt fro Rxd *
//* - Format: 9600, N, 8, 1 *
//************************************************
void InitializeUSART(void)
{
OpenUSART( USART_TX_INT_OFF // Set TXSTA Reg. =0b00100100
& USART_RX_INT_ON // Set RCSTA Reg. =0b10010000
& USART_ASYNCH_MODE
& USART_EIGHT_BIT
& USART_CONT_RX
& USART_BRGH_HIGH
,103); // Set SPBRG=103, Baud Rate = 9600

RCSTAbits.SPEN=1;
TRISCbits.TRISC7=1; // Set input for RXD
TRISCbits.TRISC6=0; // Set output for TXD
TXSTA=0b00100100;
PIR1bits.RCIF=0;
PIR1bits.TXIF=0;
IPR1bits.RCIP=1; // Set Receive of USART are High priority
}

//************************************************
//* Function: InitializePORT *
//* - Make PORTD all outputs *
//* - Turn 0ff all the LED's *
//************************************************
void InitializePORT(void)
{
PORTA=0x00;
TRISA=0b11011011; // RA2 as LCD-E control, RA5 as CS Control for SPI
PORTD=0x00;
TRISD=0x00; // Set PORTD as Output port
}


這是我剛剛嘗試的結果~還是沒反應

發表於: 2007/3/21 12:45
頂部


Re: 有關c語法的問題
#7
新會員
新會員


應該可以去嘗試判斷空字串吧'\0'

發表於: 2007/3/21 12:39
頂部


Re: 詢問pic18f452 USART傳送問題
#8
新會員
新會員


一樣也是在邏輯分析儀上仍然是沒有收到訊號
我使用的是APP001實驗版
但是我是直接使用擴充PIN上的RC6和RC7
而沒有去使用RS232接頭
這對結果會有影響嗎?
但是我有試過如果跑MCC的範例程式經由rs232接頭來傳輸的話是正常可以使用的
所以真的是搞的一個頭兩ㄍ大

發表於: 2007/3/21 12:30
頂部


Re: 詢問pic18f452 USART傳送問題
#9
新會員
新會員


有確定收到~而且有跳到傳送資料的if迴圈內
也有跳到USART的WriteUSART的函式中
可是當值傳到TXREG的時候就沒下文了
我使用邏輯分析儀去量測都沒有接收到傳送出去的數值

發表於: 2007/3/21 12:00
頂部


Re: 詢問pic18f452 USART傳送問題
#10
新會員
新會員


/* Include Header files */

#include <p18f452.h>
#include <timers.h>
#include <delays.h>
#include <usart.h>
#include <stdlib.h>
#include "P18F_LCD.h"

/* Declare the Function Prototype */
void InitializeUSART(void);
void InitializeINTs(void);
void InitializePORT(void);
void isr_high_direct(void);
void isr_high(void);

//*****************************************************
#pragma romdata My_romdata=0x1000
const rom char LCD_MSG1[]=" Power On";
const rom char LCD_MSG2[]=" Pumping Up";

#pragma romdata

//*****************************************************
#pragma udata access My_RAM_2
near unsigned char Rec_Data;
near unsigned char Data_Buffer[3];
near unsigned char Data_Temp[30];
#pragma udata

int i=0;
int j=0;

//***********************************************************
/* */
/* Main Program */
/* */
//***********************************************************

void main(void)
{
InitializePORT( );
OpenLCD( );
InitializeINTs( );
InitializeUSART( );
Rec_Data=0x00;
while(1)
{

}
}

//************************************************
//* #pragma Interrupt Declarations *
//************************************************
//************************************************
//* Function: isr_high_direct *
//* - Direct execution to the actual *
//* high-priority interrupt code. *
//************************************************
#pragma code isrhighcode = 0x0008

void isr_high_direct(void)
{
_asm //begin in-line assembly
goto isr_high //go to isr_high function
_endasm //end in-line assembly
}
#pragma code

//************************************************
//* Function: isr_high(void) *
//* High priority interrupt will *
//* - Received a serial data from RS-232 *
//* Save the received data to buffer Rec_Data*
//************************************************
#pragma interrupt isr_high

void isr_high(void)
{
Rec_Data=ReadUSART(); // Get RS-232 data; clear RCIF
Data_Buffer[i]=Rec_Data;
Data_Temp[j]=Data_Buffer[i];
if(Data_Temp[12]==0xA7 && Data_Temp[13]==0xA5 && Data_Temp[14]==0x5A )
{
while(TXSTAbits.TRMT=0);
putcUSART(0xA7);
while(TXSTAbits.TRMT=0);
putcUSART(0xA5);
while(TXSTAbits.TRMT=0);
putcUSART(0x5A);
}
if (i<3)
{
i++;
}
else
{
i=0;
}
j++;
}
#pragma code

//************************************************
//* Function: Initialize Interrupts *
//* - Reset All Interrupr *
//* - Enable HIgh Priority Interrupt *
//* - Disable Low Priority Interrupt *
//************************************************
void InitializeINTs(void)
{
PIR1=0; //Clear all Interrupt setting & Flag
PIR2=0;
INTCON=0;
INTCON2=0;
INTCON3=0;
PIE1=0;
PIE2=0;

RCONbits.IPEN=1; //Enable priority interrupts
INTCONbits.GIEL=0; // Disable Low Priority Interrupt
INTCONbits.GIEH=1; // Enalbe high priority Interrupt
}
//************************************************
//* Function: Initialize USART *
//* - Initialize the RS-232 communication *
//* - Disable Interrupr for TxD *
//* - Enable Interrupt fro Rxd *
//* - Format: 9600, N, 8, 1 *
//************************************************
void InitializeUSART(void)
{
OpenUSART( USART_TX_INT_OFF // Set TXSTA Reg. =0b00100100
& USART_RX_INT_ON // Set RCSTA Reg. =0b10010000
& USART_ASYNCH_MODE
& USART_EIGHT_BIT
& USART_CONT_RX
& USART_BRGH_HIGH
,103); // Set SPBRG=103, Baud Rate = 9600

RCSTAbits.SPEN=1;
TRISCbits.TRISC7=1; // Set input for RXD
TRISCbits.TRISC6=0; // Set output for TXD
TXSTA=0b00100100;
PIR1bits.RCIF=0;
PIR1bits.TXIF=0;
IPR1bits.RCIP=1; // Set Receive of USART are High priority
}

//************************************************
//* Function: InitializePORT *
//* - Make PORTD all outputs *
//* - Turn 0ff all the LED's *
//************************************************
void InitializePORT(void)
{
PORTA=0x00;
TRISA=0b11011011; // RA2 as LCD-E control, RA5 as CS Control for SPI
PORTD=0x00;
TRISD=0x00; // Set PORTD as Output port
}


附上全部的程式
但是目前遇到的問題在接收方面是完全正常的
可以收到我每一筆傳送的資料
但是當我要傳送的時候卻一直沒有收到傳出的Data

發表於: 2007/3/21 10:02
頂部



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

教育訓練中心

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