arkadaslar merhaba...ccs c ile programlıyorum kodlarım şu şekilde c# da programı çalıstırdığım zaman donup kalıyor
#define LCD_RS_PIN PIN_B0 //LCD baglantilari tanimlandi.
#define LCD_RW_PIN PIN_B1
#define LCD_ENABLE_PIN PIN_B2
#define LCD_DATA4 PIN_B3
#define LCD_DATA5 PIN_B4
#define LCD_DATA6 PIN_B5
#define LCD_DATA7 PIN_B6
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 8000000)
#include <lcd.c>
#use fast_io(D) // Connection pin between PIC16F877A and DHT11 (RHT01) sensor
#BIT Data_Pin = 0x08.0 // D0 pini data ile eslestirildi.
#BIT Data_Pin_Direction = 0x88.0
char yazi1[] = "Sicaklik= 00.0 C"; //Yazi kisimlari tanimlanir.
char yazi2[] = "Nem = 00.0 %";
short Time_out;
unsigned int8 S_byte1, S_byte2, N_byte1, N_byte2, CheckSum ;
#use rs232 (baud=9600, xmit=pin_C6, rcv=pin_C7, parity=N, stop=1)
#int_rda // RX ucuna veri gelince meydane gelen kesme
void serihaberlesme_kesmesi ()
{
disable_interrupts(int_rda); // int_rda kesmesini pasif yap
output_high(pin_c5); // RC5 çıkışı lojik-1
gets(yazi1); // String ifadeyi al ve "klavye" adlı dizi değişkenine aktar.
printf("\n\rYazdiginiz Metin> %s\n",yazi1); // Satır atla, yeni satır,RS232 üzerinden klavye string ifadesini gönder,satır atla
printf(lcd_putc,"\f%s",yazi1); //LCD'yi temizle ve klavye string ifadesini LCD'de göster
output_low(pin_c5); // RC5 çıkışı lojik-0
printf("\n\rKlavyeden bir metin giriniz ve enter tusuna basiniz>"); // Satır atla, yeni satır,RS232 üzerinden belirtilen metni gönder
}
void start_signal(){
Data_Pin_Direction = 0; // çikis yapildi.
Data_Pin = 0;
delay_ms(25); //25 sn bekletildi.
Data_Pin = 1; // cikis pini 1 yapildi.
delay_us(30);
Data_Pin_Direction = 1;
}
short check_response(){
delay_us(40);
if(!Data_Pin){ // düsük olan pin okundu ve test edildi.
delay_us(80);
if(Data_Pin){ //yüksek olan pin okundu ve test edildi.
delay_us(50);
return 1;}
}
}
unsigned int8 Read_Data(){
unsigned int8 i, k, _data = 0;
if(Time_out)
break;
for(i = 0; i < 8; i++){ //Sensörün datasheetine göre yazildi.
k = 0;
while(!Data_Pin){
k++;
if (k > 100) {Time_out = 1; break;}
delay_us(1);}
delay_us(30);
if(!Data_Pin)
bit_clear(_data, (7 - i));
else{
bit_set(_data, (7 - i));
while(Data_Pin){
k++;
if (k > 100) {Time_out = 1; break;}
delay_us(1);}
}
}
return _data;
}
void main(){
lcd_init(); // LCD hazir hale getirildi.
lcd_putc('\f'); // LCD temizlenir.
enable_interrupts(GLOBAL);
while(TRUE){
enable_interrupts(int_rda); // int_rda kesmesi aktif
delay_ms(1000);
Time_out = 0;
Start_signal();
if(check_response()){ // Sensörden yanit var mi kontrol edilir.
N_byte1 = Read_Data(); // N 1.biti okunur
N_byte2 = Read_Data(); // N 2.biti okunur.
S_byte1 = Read_Data(); // S 1.biti okunur.
S_byte2 = Read_Data(); // S 2.biti okunur.
Checksum = Read_Data(); // Chacksum okunur.
if(Time_out){
lcd_putc('\f'); // LCD temizlenir.
lcd_gotoxy(5, 1);
lcd_putc("Zaman Asimi");
}
else{
if(CheckSum == ((N_Byte1 + N_Byte2 + S_Byte1 + S_Byte2) & 0xFF)){
yazi1[10] = S_Byte1/10 + 48;
yazi1[11] = S_Byte1%10 + 48;
yazi1[13] = S_Byte2/10 + 48;
yazi2[10] = N_Byte1/10 + 48;
yazi2[11] = N_Byte1%10 + 48;
yazi2[13] = N_Byte2/10 + 48;
yazi1[14] = 223;
lcd_putc('\f'); // LCD temizlenir.
lcd_gotoxy(1, 1);
printf(lcd_putc, yazi1);
lcd_gotoxy(1, 2);
printf(lcd_putc, yazi2);
}
else {
lcd_putc('\f');
lcd_gotoxy(1, 1);
lcd_putc("Checksum hatasi!");
}
}
}
else {
lcd_putc('\f');
lcd_gotoxy(3, 1);
lcd_putc("Sonuc yok");
lcd_gotoxy(1, 2);
lcd_putc("Sensöre gelen");
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.IO;
namespace seri_port_veri_okuma
{
public partial class Form1 : Form
{
string data;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
data = serialPort1.ReadExisting();
label1.Text = data + "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
timer1.Stop();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (!serialPort1.IsOpen)
{
serialPort1.Open();
}
data = serialPort1.ReadLine();
label1.Text = data;
}
}
}
timerla yaparsan hata yaparsın.
https://www.codeproject.com/Articles/75770/Basic-serial-port-listening-application