![]() |
|
Tài trợ cho PIC Vietnam |
||||||||
| dsPIC - Bộ điều khiển tín hiệu số 16-bit Theo dự kiến của Microchip, vào khoảng năm 2011 dsPIC sẽ có doanh số lớn hơn PIC |
![]() |
|
|
Ðiều Chỉnh | Xếp Bài |
|
|
|
|
#1 | |
|
Đệ tử 5 túi
Tham gia ngày: Sep 2007
Bài gửi: 94
: |
Trích:
|
|
|
|
|
|
|
#2 |
|
Đệ tử 4 túi
Tham gia ngày: Jul 2008
Bài gửi: 61
: |
|
|
|
|
|
|
#3 |
|
Đệ tử 4 túi
Tham gia ngày: Mar 2009
Bài gửi: 64
: |
Code:
#include <p33FJ256GP710.h>
#include "uart.h"
//CASE4: Star-up using internal FRC, after that switching to Primary Oscillator with PLL
_FOSCSEL(FNOSC_FRC);// Select Internal FRC at POR
_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT);// Enable Clock Switching and Configure POSC in XT mode
_FWDT(FWDTEN_OFF);// Watchdog Timer Enabled/disabled by user software
_FGS(GCP_OFF); //Code protect off
//************************************************
void Oscillatior_configuration(void)
{
//Fcy=Fosc/2 (always), Fin/N1 = (0~8MHz), Fin/N1*M = (100~200MHz), Fin/N1*M/N2 = (12.5~80MHz)
//M(2->253) , N1(2->33), N2(2,4,8)
//If using PLL: Fosc= Fin*M/(N1*N2)
//For primary oscillator, xt mode with PLL. Fin = 8MHz, =>Fosc = 80MHz, Fcy = 40Mips
// Configure PLL prescaler, PLL postscaler, PLL divisor
PLLFBD = 38; /* M=30 */
CLKDIVbits.PLLPOST = 0; /* N1=2 */
CLKDIVbits.PLLPRE = 0; /* N2=2 */
// Initiate Clock Switch to Primary Oscillator with PLL (NOSC = 0b011)
__builtin_write_OSCCONH(0x03);
__builtin_write_OSCCONL(0x01);
// Wait for Clock switch to occur
while (OSCCONbits.COSC != 0b011); //COSC update new value from NOSC when switching successful
// Wait for PLL to lock
while(OSCCONbits.LOCK!=1) {};
}
int main()
{ int i;
//configure crystal
Oscillatior_configuration();
// UART1 initialization
OpenUART1(0xC000,0x0550,0x80); //status chua dung lam'
//Send string
putsUART1((unsigned int*)"\n\rThis is a simple UART1 test\n\r");
for(i=0;i<=9;i++)
{
while(BusyUART1()); //Wait
WriteUART1(0x30+i); //Send character
}
CloseUART1();
}
nhớ include uart.h nhé...để nó còn biết các hàm putsUART1 và WriteUART1 khuyến mãi thêm hàm đểu , gửi số kiểu int lên terminal Code:
putiUART1(unsigned int number)
{ char buf[5];
sprintf(buf,"%u",number);
putsUART1((unsigned int*)buf);
}
|
|
|
|
![]() |
|
|