Mert Can Bilgiç
Üye
- Katılım
- 9 Ocak 2016
- Mesajlar
- 100
- Puanları
- 1
- Yaş
- 24
Arkadaşlar herkese iyi forumlar. 16F877A VE HC-05 kullanarak okuduğum bir değeri bluetooth ile mobil uygulamada görüntülemeye çalışıyorum ama bir türlü çalıştıramadım. Bluetooth ile led yak-söndür yapabiliyorum modülde bir sıkıntı yok yani. İlk önce B0'a bağlı butona basarak data değişkenini arttırıp bu değeri görüntülemek istedim.
4MHz'lik osilatör kullanıyorum. Kullandığım derleyici ise MPLAB XC8.
Şimdiden teşekkür ediyorum. İyi forumlar.
4MHz'lik osilatör kullanıyorum. Kullandığım derleyici ise MPLAB XC8.
Kod:
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include <stdint.h>
#define _XTAL_FREQ 4000000
void UART_TX_Init(void);
void UART_Write(uint8_t);
void main(void)
{
UART_TX_Init(); // Initialize The UART in Master Mode @ 9600bps
uint8_t Data = 0;
TRISB = 1;
RB7 = 0;
while(1) {
if (RB0 == 1) {
RB7 = 1;
Data++;
__delay_ms(250);
}
else {
RB7=0;
}
}
UART_Write(Data);
return;
}
void UART_TX_Init(void)
{
BRGH = 1; // Set For High-Speed Baud Rate
SPBRG = 25; // Set The Baud Rate To Be 9600 bps
//--[ Enable The Ascynchronous Serial Port ]--
SYNC = 0;
SPEN = 1;
//--[ Set The RX-TX Pins to be in UART mode (not io) ]--
TRISC6 = 1; // As stated in the datasheet
TRISC7 = 1; // As stated in the datasheet
TXEN = 1; // Enable UART Transmission
}
void UART_Write(uint8_t data)
{
while(!TRMT);
TXREG = data;
}
Şimdiden teşekkür ediyorum. İyi forumlar.