kidteam
Junior Member level 3
hi all i'm a newbie
when i use euart's pic16f887 with hi-tech C, it work fine
but it not work when i use mikro C
please help me
code HTC work fine
and code MikroC not work
when i use euart's pic16f887 with hi-tech C, it work fine
but it not work when i use mikro C
please help me
code HTC work fine
Code:
#include <htc.h>
//#include <pic.h>
__CONFIG(FOSC_XT&WDTE_OFF&PWRTE_ON&MCLRE_OFF&CP_OFF&CPD_OFF&BOREN_OFF&IESO_OFF&FCMEN_OFF&LVP_OFF&DEBUG_OFF);
__CONFIG(BOR4V_BOR40V&WRT_OFF);
//dau tien ta thu cho xuat ra 8 led tai cong b
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif
unsigned char c;
void main() {
ANSEL=ANSELH=0;
TRISB=0;//cong B lam cong ra
TRISC7=1;//RxD //chan vao
TRISC6=0;//TxD //chan ra
//khoi tao toc do baurd
SYNC=0;
BRGH=1;
BRG16=0;
SPBRG=25;
//toc do baurd 9600
SPEN=1;
RX9=0;
CREN=1;//cho phep nhan
RCIF=0;
TXIF=0;
TXEN=1;//cho phep truyen
PORTB=0x00;
while(1) {
//chu y o day ta dung hoi vong thoi
//chua dung den ngat
while(!RCIF){ //cho cho den khi nhan duoc thi thoi
}//cho
RCIF=0;
c=RCREG;
if(c=='A') {
PORTB=0xff;
//__delay_ms(10);
TXREG='C';
while(!TXIF);//cho gui xong
TXIF=0;
} else {
if(c=='B') {
PORTB=0x00;
//__delay_ms(10);
TXREG='D';
while(!TXIF);
TXIF=0;
}
}
}
}
Code:
void main(){
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
TRISB = 0x00; // Set PORTB as output (error signalization)
PORTB = 0; // No error
UART1_Init(9600);
Delay_Ms(100);
while(1) {
UART1_Write('A');
Delay_Ms(100);
}
}