Devre şeması aşağıdaki gibidir. 4mhz kristal kullanılmış olup ona bağlı olan 22pf kondansatördür.
char uart_rd; // EUSART biriminden alınacak olan veri için
// tanımlanan değişken
// LCD display bağlantıları
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D7_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD0_bit;
// LCD display bağlantı sonu
void main(){
TRISB=0X00;
PORTB=0X00;
ADCON1 |= 0x0F; // AN pinleri dijital I/O yapılandırıldı
CMCON |= 7; // Comparators (karşılaştırıcılar) pasif edildi
Lcd_Init(); // LCD display yapılandırıldı
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD ekranından imleç kaldırıldı
Lcd_Cmd(_LCD_CLEAR); // LCD ekranı silindi
Lcd_Out(1, 3, " muhhakanaydin"); // 1. satır, 3. sütun'a text yazdırıldı
Lcd_Out(2, 1, ".blogspot.com.tr"); // 2. satır, 1. sütun'a text yazdırıldı
UART1_Init(9600); // EUSART donanımı yapılandırıldı
Delay_ms(100); // Baud hızı 57600 belirlendi
for( ; ; )
{
if (UART1_Data_Ready()) { // Şayet EUSART'dan veri geldi ise,
uart_rd = UART1_Read(); // Alınan veriyi oku, uart_rd'ye al,
UART1_Write(uart_rd); // ve EUSART'a veriyi yaz
Lcd_Chr_Cp(uart_rd); // Alınan veriyi LCD ekranına gönder
if (uart_rd == '9') LCD_CMD(_LCD_CLEAR); // ESC display ekranını sil
if (uart_rd == '0') PORTB=1;
if (uart_rd == '1') PORTB=2;
if (uart_rd == '2') PORTB=4;
if (uart_rd == '3') PORTB=8;
if (uart_rd == '4') PORTB=16;
if (uart_rd == '5') PORTB=32;
if (uart_rd == '6') PORTB=64;
if (uart_rd == '7') PORTB=128;
}
}
}
Java ile ilgili olan GUI ve kodu;
import jssc.SerialPort;
import jssc.SerialPort;
import jssc.SerialPortException;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel2 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setBackground(new java.awt.Color(0, 255, 255));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "LCD EKRAN", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 3, 18), new java.awt.Color(255, 0, 0))); // NOI18N
jButton1.setText("EKRAN SIL");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setText("LCD EKRANA YAZDIR");
jButton2.setText("YAZDIR");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jButton2))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton2))
);
jPanel1.setBackground(new java.awt.Color(0, 0, 204));
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(51, 255, 0)));
jButton3.setText("LED 1");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("LED 2");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setText("LED 3");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setText("LED 4");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jButton7.setText("LED 5");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
jButton8.setText("LED 6");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});
jButton9.setText("LED 7");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});
jButton10.setText("LED 8");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton10)
.addContainerGap(30, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton3)
.addComponent(jButton4)
.addComponent(jButton5)
.addComponent(jButton6)
.addComponent(jButton7)
.addComponent(jButton8)
.addComponent(jButton9)
.addComponent(jButton10))
.addContainerGap(19, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes("9".getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(String.valueOf(jTextField1.getText()).getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(String.valueOf("0").getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(String.valueOf("1").getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(String.valueOf("2").getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(String.valueOf("3").getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(String.valueOf("4").getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(String.valueOf("5").getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(String.valueOf("6").getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
SerialPort serialPort = new SerialPort("COM6");
try {
serialPort.openPort();
serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes(String.valueOf("7").getBytes());
serialPort.closePort();
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
public static void main(String args[]) {
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
Bu çalışmaya başlamadan evvel bu kaynaktaki gibi sizde ayarlamaları yapmalısınız.
Kaynak
http://code.google.com/p/java-simple-serial-connector/wiki/jSSC_Start_Working
SONUC
Hiç yorum yok:
Yorum Gönder