• slider image 442
  • slider image 492
  • slider image 493
  • slider image 494
  • slider image 495
  • slider image 496
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






pwm
#1
新會員
新會員


查看用戶資訊
各位高手....
我寫了一個簡單的抓pwm程式,可是想請問是否可以讓我的程式執行下來更有效率,以方便我抓到更小的pwm波寬值,麻煩高手指教,謝謝。
我的程式如下:
#include <p18f452.h>
#include <usart.h>
#include <delays.h>
#include <timers.h>
#include <stdlib.h>
#include <portb.h>

#define UART_40Mhz_19200 129


void external_int(void);

unsigned char a[7];
unsigned char PWM_out[8];


union
{
unsigned char One_Byte[2];
unsigned int Two_Byte[1];
}Buff;


#pragma code high_vector=0x0008 // high priotity interrupt isr
void high_interrupt (void)
{_asm goto external_int _endasm}
#pragma code

//********* Port B chagne detect *********
#pragma interrupt external_int

void external_int()
{
//** INT0 **********************************************
if(INTCONbits.INT0IF){
WriteTimer1(0);
TMR1H=0;
TMR1L=0;
INTCONbits.INT0IF=0; // clear INT0IF

}

//**** INT 1 **********************************************
if(INTCON3bits.INT1IF){
//x=ReadTimer1();
Buff.One_Byte[0]=TMR1L;
Buff.One_Byte[1]=TMR1H;
INTCON3bits.INT1IF=0;
}
}
#pragma

//**********************************************//
void main(){
// Setup UART for 9600bps with 20MHZ for high speed
OpenUSART(USART_TX_INT_OFF&
USART_RX_INT_OFF&
USART_ASYNCH_MODE&
USART_EIGHT_BIT&
USART_CONT_RX&
USART_BRGH_HIGH,UART_40Mhz_19200);
//Setup Timer1
OpenTimer1(TIMER_INT_OFF&
T1_16BIT_RW&
T1_SOURCE_INT&
T1_PS_1_1);

//Initialize Ports
TRISB=0b00000011;// set RB5-RB4 for input on change
TRISCbits.TRISC2=1;// CCP1
TRISCbits.TRISC6=0;
TRISCbits.TRISC7=1;

TRISD=0; // PORTD all output
PORTB=0;
PORTD=0;

// Set up interrupt control bit
PIR1bits.TMR1IF=0; // clear timer1 IF

// setup INT0
INTCONbits.INT0IE=1;
INTCONbits.INT0IF=0;
INTCON2bits.INTEDG0=1;// set INT0 for Rising Edge

// setup INT1
INTCON3bits.INT1IE=1;
INTCON3bits.INT1IF=0;
INTCON2bits.INTEDG1=0;// set INT1 for Falling Edge
INTCON3bits.INT1IP=1;// set for Low Priority

RCONbits.IPEN=1; // enable priority interrupt
INTCONbits.PEIE=1;// enable peripheral interrupt
INTCONbits.GIE=1;// enable global interrupt

putrsUSART("\r AS5040 PWM Measurement \n\r");

while(1)
{
//ltoa(x,a);
ltoa(Buff.Two_Byte[0],PWM_out);
putrsUSART("\rPWM ");
Delay10KTCYx(1);
//putsUSART(a);

putsUSART(PWM_out);
putrsUSART("\n");
}

}



發表於: 2005/7/5 8:04
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... ]

教育訓練中心

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