Devre bu sekildedir.PIC F628A kullanılmıştır.Program satırları bu şekildedir.#include <16f628A.h>
#use delay(CLOCK=4000000)
#use fast_io(a)
#use fast_io(b)
#fuses XT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NOWDT
#use rs232 (baud=9600, xmit=PIN_B2, RCV=PIN_B1, parity=N, stop=1)
int temp=1;
#INT_RDA
void seri_kesme()
{
disable_interrupts(INT_RDA);
temp=getc();
}
void main()
{
set_tris_b(0x02);
set_tris_a(0x00);
output_b(0x00);
output_a(0x00);
enable_interrupts(GLOBAL);
while(true)
{
enable_interrupts(int_rda);
if(temp==121)
{ temp=0X00;
output_high(pin_a0);
}
if(temp==122)
{ temp=0X00;
output_high(pin_a1);
}
if(temp==123)
{ temp=0X00;
output_high(pin_a2);
}
if(temp==1241)
{ temp=0X00;
output_high(pin_a3);
}
if(temp==125)
{ temp=0X00;
output_low(pin_a0);
}
if(temp==126)
{ temp=0X00;
output_low(pin_a1);
}
if(temp==127)
{ temp=0X00;
output_low(pin_a2);
}
if(temp==1281)
{ temp=0X00;
output_low(pin_a3);
}
Arayüz javada yazılmıştır.
package tgb;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.DataInputStream;
import java.io.DataOutputStream;
public class SerialBaglanti
{
CommPortIdentifier kimlik;
CommPort commPort;
SerialPort serialPort;
DataInputStream in;
DataOutputStream out;
int connect ( String portName )
{
try {
kimlik = CommPortIdentifier.getPortIdentifier(portName);
commPort = kimlik.open(this.getClass().getName(),2000);
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
in =new DataInputStream(serialPort.getInputStream());
out =new DataOutputStream(serialPort.getOutputStream());
} catch (Exception e) {
return 4;
}
return 3;
}
int yaz(int veri){
try {
out.write(veri);
} catch (Exception e) {return 4;}
return 0;
}
Burada ise programın devamı görülmektedir.
public class TurgutSerial extends javax.swing.JFrame {
String com="COM1";
public TurgutSerial() {
initComponents();
SerialBaglanti a = new SerialBaglanti();//SERİ İLETİŞİM İÇİN
int bb=a.connect(com);
jToggleButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JToggleButton tBtn = (JToggleButton)e.getSource();
if (tBtn.isSelected()) {
jToggleButton1.setText("Açık");
a.yaz(121);
} else {
jToggleButton1.setText("Kapalı");
a.yaz(125);
}
}});
jToggleButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JToggleButton tBtn = (JToggleButton)e.getSource();
if (tBtn.isSelected()) {
jToggleButton2.setText("Açık");
a.yaz(122);
} else {
jToggleButton2.setText("Kapalı");
a.yaz(126);
}
}});
jToggleButton3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JToggleButton tBtn = (JToggleButton)e.getSource();
if (tBtn.isSelected()) {
jToggleButton3.setText("Açık");
a.yaz(123);
} else {
jToggleButton3.setText("Kapalı");
a.yaz(127);
}
}});
jToggleButton4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JToggleButton tBtn = (JToggleButton)e.getSource();
if (tBtn.isSelected()) {
jToggleButton4.setText("Açık");
a.yaz(1241);
} else {
jToggleButton4.setText("Kapalı");
a.yaz(1281);
}
}});
Hiç yorum yok:
Yorum Gönder