Category Archives: AVR

Dasar arsitektur AVR

Pengetahuan Dasar Simpan Data Char Integer dan Array di EEPROM

Contoh Code -1

void writeInteger(int addr, int dataeeprom)
{
writeeeprom(addr+1, dataeeprom & 0xff);
writeeeprom(addr, (dataeeprom>>8) & 0xff);
}

int ReadInteger(int addr)
{ char value=0,value2=0;
value = readeeprom(addr);
value2 = readeeprom(++addr);
value = (value <<8) & 0xff00;
value = value | value2;
return value;
}

void writeeeprom(unsigned int alamat, unsigned char datana)
{
while(EECR & (1<<1));
EEAR = alamat;
EEDR = datana;
EECR |= (1<<2);
EECR |= (1<<1);
delay_ms(10);
}
unsigned char readeeprom(unsigned int alamat)
{
unsigned char dataeeprom;
while(EECR & (1<<1));
EEAR = alamat;
EECR |= (1<<0);
dataeeprom=EEDR;
return dataeeprom;
delay_ms(10);
}

void simpanArrayKeEEPROM( int array[],int alamat)
{ char i=0;

for(i=0;i<13;i++)
{
writeInteger(alamat, array[i]) ;
alamat=alamat+2;
}
}

 

Contoh Kode -2 dgn menggunakan library EEPROM

#include <EEPROM.h>

void writeEepromInteger(int addr, unsigned int dataeeprom)
{
EEPROM.write(addr+1, dataeeprom & 0xff);
EEPROM.write(addr, (dataeeprom>>8) & 0xff);
delay(50);
}

int readEepromInteger(int addr)
{
int value = EEPROM.read(addr);
int value2 = EEPROM.read(++addr);
value = (value <<8) & 0xff00;
value = value | value2;
return value;
}

//contoh penggunaan fungsi writeEepromInteger()  diatas

writeEepromInteger(1,1500);   // write intger 1500 ke alamat 1 dan 2 dimemori eeprom
writeEepromInteger(4,6789);   // write intger 6789 ke alamat 4 dan 5 dimemori eeprom

//contoh penggunaan fungsi readeepromInteger()  diatas

int dataku =readEepromInteger(1);   //baca Eeprom alamat 1 dan 2 simpan sebagai integer di variable dataku

int datamu =readEepromInteger(4);

Advertisements

Pengetahuan Dasar Membuat Grafik Real Time VB.Net Data Serial Port Arduino

Pengetahuan Dasar Membuat Grafik Real Time Data Serial Port

Aplikasi yg dibutuhkan
VB.Net
Codevision atau Arduino

ARDUINO_MODUL

Hardware yg dibutuhkan
Usb to Serial
Mikrocontroller board AVR atau Arduino board

Tahapan Pembuatan aplikasi VB.Net

-Buka project baru

-pada form tambahkan komponen Chart,timer, textbox,listbox  dan button

-Atur tata letak komponen chart,textbox,buton pada form

graph

Kode ProgramVB.Net 2010
Imports System
Imports System.IO.Ports
Imports System.Threading
Imports System.Threading.Thread
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Dim data As String
Dim frek As String
Dim RXArray(2047) As Char
Dim RXCnt As Integer ‘
Dim time As String
Dim frekwensi As String
Dim engChart As New Series

Dim WithEvents COMPort As New SerialPort

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub
Private Sub ClosePort()
If COMPort.IsOpen Then
COMPort.Close()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If COMPort.IsOpen Then
COMPort.Close()
Label3.Text = “koneksi berhasil ditutup”

End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each COMString As String In My.Computer.Ports.SerialPortNames
ComboBox1.Items.Add(COMString)
Next
Chart1.Series.Clear()
Chart1.Titles.Add(“data serial real time”)
engChart.Name = “analog in”
engChart.ChartType = SeriesChartType.Line
Chart1.Series.Add(engChart)
Chart1.ForeColor = Color.Cyan
ComboBox1.Focus()
RXCnt = 0

End Sub

‘=================================================================

‘=================================================================
Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMPort.DataReceived
Dim RXByte As Byte

Do
RXByte = COMPort.ReadByte
RXArray(RXCnt) = Chr(RXByte)

If Chr(RXByte) = Chr(13) Then
Me.Invoke(New MethodInvoker(AddressOf Display))
RXCnt = 0
End If
RXCnt = RXCnt + 1

Loop Until (COMPort.BytesToRead = 0)
End Sub

Private Sub Display()
data = (New String(RXArray, 1, RXCnt))

TextBox1.Text = data

DoUpdate()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
time = TimeOfDay
End Sub
Public Sub DoUpdate()

Try
engChart.Points.AddXY(time, data)
Catch ex As Exception

Label3.Text = ex.Message
Finally

End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If COMPort.IsOpen Then
COMPort.RtsEnable = False
COMPort.DtrEnable = False
ClosePort()

Application.DoEvents()
Sleep(200)
End If
COMPort.PortName = ComboBox1.Text
COMPort.BaudRate = 9600
COMPort.WriteTimeout = 2000
Try
COMPort.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try

If COMPort.IsOpen Then
COMPort.RtsEnable = True
COMPort.DtrEnable = True

Label3.Text = “koneksi berhasil dibuka”
End If
End Sub
End Class

kode program Arduino
void setup() {
Serial.begin(9600);
}
void loop() {
// baca  analog pin 0:
int sensorValue = analogRead(A0);
// kirim hasil ke serial
Serial.println(sensorValue);
delay(1000);
}

Kode progrtam AVR codevision

/*****************************************************
Date : 13/08/2016
Chip type : ATmega16
Clock frequency : 11,059200 MHz
kontinyu kirim data :50987<0D>60734<0D>dst..
*****************************************************/

#include <mega16.h>
#include <stdio.h>
#include <delay.h>

unsigned int i;
void main(void)
{
// 8 Data, 1 Stop, No Parity
// Baud rate: 9600
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

while (1)
{
i++;
putchar(i/1000 %10 + 0x30);
putchar( i/100 %10 + 0x30);
putchar(i/10 %10 + 0x30);
putchar(‘.’);
putchar(i % 10 + 0x30);
putchar(‘\r’) ;
delay_ms(600);

};
}

promoarduinovbnet

Membuat Display 4 baris 7 segment menggunakan MAX7221

Teory dasar bisa dibaca di https://pccontrol.wordpress.com/2011/09/15/pemrograman-display-7-segment-dengan-spi-max7221-max7219/

pada contoh ini menggunakan 7 segment  kecil < 1 inch dgn tegangan 5v.jika Anda ingin menggunakan 7 segmen dgn tegangan lebih dari 5 v ( 7 segment ukuran yg besar i inch,2 inch 3 inch dst) maka tinggalditambahkan penguat daya misal dgn transistor atau ic ULN2083 atau lainnya.

4baris7segment

koneksi

max7221serial

Kode program C dengan codevision

 

/*****************************************************
CodeWizardAVR V1.24.
Chip type : ATmega16
Clock frequency : 11.059200 MHz
*****************************************************/
// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>
#include <spi.h>
#include <mega16.h>
//=========================

// SPI
#define PIN_SCK PORTB.7
#define PIN_MOSI PORTB.5
#define PIN_SS PORTB.4

#define ON 1
#define OFF 0

#define MAX7219_LOADa1 PORTB.4=1 //chip enable 1
#define MAX7219_LOADa0 PORTB.4=0 //chip enable 0
#define MAX7219_LOADb1 PORTB.3=1 //chip enable 1
#define MAX7219_LOADb0 PORTB.3=0 //chip enable 0
#define MAX7219_LOADc1 PORTB.2=1 //chip enable 1
#define MAX7219_LOADc0 PORTB.2=0 //chip enable 0
#define MAX7219_LOADd1 PORTB.1=1 //chip enable 1
#define MAX7219_LOADd0 PORTB.1=0 //chip enable 0

#define MAX7219_MODE_DECODE 0x09
#define MAX7219_MODE_INTENSITY 0x0A
#define MAX7219_MODE_SCAN_LIMIT 0x0B
#define MAX7219_MODE_POWER 0x0C
#define MAX7219_MODE_TEST 0x0F
#define MAX7219_MODE_NOOP 0x00

#define MAX7219_DIGIT0 0x01
#define MAX7219_DIGIT1 0x02
#define MAX7219_DIGIT2 0x03
#define MAX7219_DIGIT3 0x04
#define MAX7219_DIGIT4 0x05
#define MAX7219_CHAR_BLANK 0xF
#define MAX7219_CHAR_NEGATIVE 0xA
//================================
#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7

#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)

//void MAX7219_displayNumber(volatile long number);
void MAX7219_displayNumber(long number,char baris);
void MAX7219_clearDisplay(char baris);
//void MAX7219_writeData(char data_register, char data);
void MAX7219_writeData(char data_register, char data, char baris);
void spiSendByte (char databyte);

// USART Receiver buffer
#define RX_BUFFER_SIZE 8
char rx_buffer[RX_BUFFER_SIZE];

#if RX_BUFFER_SIZE<256
unsigned char rx_wr_index,rx_rd_index,rx_counter;
#else
unsigned int rx_wr_index,rx_rd_index,rx_counter;
#endif

// This flag is set on USART Receiver buffer overflow
bit rx_buffer_overflow;

// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
{
rx_buffer[rx_wr_index]=data;
if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
if (++rx_counter == RX_BUFFER_SIZE)
{
rx_counter=0;
rx_buffer_overflow=1;
};
};
}

#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter==0);
data=rx_buffer[rx_rd_index];
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
#asm(“cli”)
–rx_counter;
#asm(“sei”)
return data;
}
#pragma used-
#endif

// Declare your global variables here
char digitsInUse = 5;
void main(void)
{
// Declare your local variables here

int a,b,c,d,i;
// Input/Output Ports initialization
// Port A initialization
PORTA=0x00;
DDRA=0x00;

// Port B initialization
PORTB=0x00;
DDRB=0xff; // SCK MOSI CS/LOAD/SS

// Port C initialization
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: Off
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x90;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 86.400 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
//SPCR=0x53;
//SPSR=0x00;
// SPI Enable, Master mode
SPCR =0x53;
for(i=1;i<5;i++)
{
// Decode mode to “Font Code-B”
MAX7219_writeData(MAX7219_MODE_DECODE, 0xFF,i);
// Scan limit runs from 0.
MAX7219_writeData(MAX7219_MODE_SCAN_LIMIT, digitsInUse – 1,i);
MAX7219_writeData(MAX7219_MODE_INTENSITY, 8,i);
MAX7219_writeData(MAX7219_MODE_POWER, ON,i);
delay_ms(50);
}
//

// Global enable interrupts
#asm(“sei”)

a=12305;
b=11300;
c=11612;
d=b-c;
MAX7219_displayNumber(a,1);
MAX7219_displayNumber(b,2);
MAX7219_displayNumber(c,3);
MAX7219_displayNumber(d,4);

while (1)
{

i=i+1;

if(i==999)i=0;
};

}

//===============================================================================
//=========================
void spiSendByte (char databyte)
{
SPDR = databyte;
// Wait until transfer is complete
while (!(SPSR & (1 << 7)));
}

void MAX7219_writeData(char data_register, char data, char baris)
{
if(baris==1)
{
MAX7219_LOADa0;
// Send the register where the data will be stored
spiSendByte(data_register);
// Send the data to be stored
spiSendByte(data);
MAX7219_LOADa1;
}
if(baris==2)
{
MAX7219_LOADb0;
// Send the register where the data will be stored
spiSendByte(data_register);
// Send the data to be stored
spiSendByte(data);
MAX7219_LOADb1;
}
if(baris==3)
{
MAX7219_LOADc0;
// Send the register where the data will be stored
spiSendByte(data_register);
// Send the data to be stored
spiSendByte(data);
MAX7219_LOADc1;
}
if(baris==4)
{
MAX7219_LOADd0;
// Send the register where the data will be stored
spiSendByte(data_register);
// Send the data to be stored
spiSendByte(data);
MAX7219_LOADd1;
}

}

void MAX7219_clearDisplay(char baris)
{
char i;
i = digitsInUse;
// Loop until 0, but don’t run for zero
do {
// Set each display in use to blank
MAX7219_writeData(i, MAX7219_CHAR_BLANK,baris);
} while (–i);

}

void MAX7219_displayNumber(long number,char baris)
{
char negative = 0;
char i = 0;
if (number < 0) {
negative = 1;
number =number * -1; //rubah ke +
}
MAX7219_clearDisplay(baris);
// If number = 0, only show one zero then exit
if (number == 0) {
MAX7219_writeData(1, 0,baris);
return;
}
// Initialization to 0 required in this case,
// does not work without it. Not sure why.
// Loop until number is 0.
do {
MAX7219_writeData(++i, number % 10,baris);
// Actually divide by 10 now.
number /= 10;
} while (number);

// display the sign.
if (negative) {
MAX7219_writeData(i+1, MAX7219_CHAR_NEGATIVE,baris);
}
}

Membuat Interface Board Untuk Latihan Input-Output, komunikasi RS232 dan RS485

Selain kita belajar mikrokontroller  melalui simulasi sebaiknya kita juga mencobanya dalam dlm keadaan sebenarnya.karena ada beberapa karakteristik elictrical yg tidak masuk dalam parameter di simulator.

Kita akan membuat sebuah board Input output dan komunikasi yg bisa dikoneksi  oleh systim minimum yg ada di pasaran. berikut ini blok diagramnya:

blogdigram

Dari gambar diatas bagian yg akan kita buat adalh interface board , dengan interface sbb:

  • 4 buah output 9-50 V DC   (tergantung daya yg diberikan)
  • 1 input sensor NPN standar industri (12/24v DC)
  • Komunikasi RS485
  • Komunikasi RS232

baiklah langsung saja kita buat rangkaian pada IDE eagle  sbb:

interfacesircuit

tambahkan rangkaian RS232

rs232circuit

setelah selesai circuit dibuat kita menuju board

Atur ukuran PCB dan tata letak komponen diboard sesuai kebutuhan Anda. kalau saya buatnya sbb:

interfaceboard

Interface Board  dengan ukuran 62mm  x 101mm ,sy buat ukuran tersebut untuk menyesuaikan dgn Casing yg tersedia yg sy punya.

casingboxlatihan

Dimensi Casing Almunium : tingggi 16cm (160mm), lebar 10cm (100mm) tinggi casing bagian dalamsekitar 5cm(50mm). dan ketebalan plat almunium sekitar 2,5mm

Berikut ini penampakan interface board yang sudah jadi :

interfaceboard

Penjelasan Masing masing bagian/fungsi dalam interface board:

  1. Dip Switch   ,  digunakan untuk input data  digital   dan  kombinasi dari dip switch bisa digunakan untuk alamat  pada percobaan komunikasi RS485. dipswitch
  2. Komunikasi RS485  digunakan untuk komunikasi ke banyak microcontroller.rs485circuite
  3. Output Penguat Daya ULN2803  bisa digunakan menggerakan device  yg mempunyai tegangan 6-50v. uln2083circuite
  4. Input  dgn Opto Coupler  , untuk dihubungkan ke sensor industri  atau juga switch on off. optocircuite
  5. Komunikasi RS232  digunakan untuk komunikasi ke PCrs232circuit

tobe continue….

 

 

Pengetahuan dasar Pemrograman Led Matrix

Scan

ledmatrix

Untuk menampilkan karakter ke sebuah segment kita harus menyalakan  led per kolom secara bergantian(scanning) terus menerus.  Karena  frekwensi scanning  cepat  sehingga semua led  terlihat seolah menyala bersamaan.

ledmatrix2.jpg

untuk karakter A maka kode untuk tiap kolom yg akan di scan adalah

kolom ke-1=0x7E , ke-2 : 0x09, ke-3 :0x09, ke-4: 0x7E, & kolom ke-5:0x7E

step/urutan menampilkan huruf A

kirim 0x7E  aktifkan kolom ke-1

kirim 0x09  aktifkan kolom ke-2

kirim 0x09  aktifkan kolom ke-3

kirim 0x7E  aktifkan kolom ke-4

 

berikut Contoh Program

/*****************************************************
Chip type : ATmega16
Program type : Application
Clock frequency : 11,059200 MHz
*****************************************************/

#include <mega16.h>
#include <delay.h>
// External Interrupt 0 service routine
unsigned short count, column, num, repeat,i;
unsigned char data[4]={‘A’,’B’,’C’,’0′};
void displayLEDmatrix(char huruf);

// Declare your global variables here
unsigned short Alphabets[130]={ 0x7E, 0x09, 0x09, 0x7E, 0xFF, // A
0x7f, 0x49, 0x49, 0x49, 0x36, // B
0x3e, 0x41, 0x41, 0x41, 0x22, // C
0x7f, 0x41, 0x41,0x22, 0x1c,
0x7f, 0x49, 0x49, 0x49, 0x63,
0x7f, 0x09, 0x09, 0x09, 0x01,
0x3e, 0x41, 0x41, 0x49, 0x7a,
0x7f, 0x08, 0x08, 0x08, 0x7f,
0x00, 0x41, 0x7f, 0x41, 0x00, // I
0x20, 0x40, 0x41, 0x3f, 0x01,
0x7f, 0x08, 0x14, 0x22, 0x41,
0x7f, 0x40, 0x40, 0x40, 0x60,
0x7f, 0x02, 0x04, 0x02, 0x7f,
0x7f, 0x04, 0x08, 0x10, 0x7f,
0x3e, 0x41, 0x41, 0x41, 0x3e,
0x7f, 0x09, 0x09, 0x09, 0x06,
0x3e, 0x41, 0x51, 0x21, 0x5e,
0x7f, 0x09, 0x19, 0x29, 0x46,
0x46, 0x49, 0x49, 0x49, 0x31, // S
0x01, 0x01, 0x7f, 0x01, 0x01,
0x3f, 0x40, 0x40, 0x40, 0x3f,
0x1f, 0x20, 0x40, 0x20, 0x1f,
0x3f, 0x40, 0x30, 0x40, 0x3f,
0x63, 0x14, 0x08, 0x14, 0x63,
0x07, 0x08, 0x70, 0x08, 0x07,
0x61, 0x51, 0x49, 0x45, 0x43 // Z
};

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=1 State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
PORTA=0x7F;
DDRA=0xFF;

// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=1 State2=1 State1=1 State0=1
PORTB=0x0F;
DDRB=0xFF;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=P State2=P State1=P State0=P
PORTD=0x0F;
DDRD=0x00;
// Global enable interrupts
#asm(“sei”)

while (1){
// huruf A mulai index array 0-5
//huruf B mulai index array 6-11
//dst

for(i=0;i<5;i++ )
{

displayLEDmatrix(data[i]);

}

};
}
void displayLEDmatrix(char huruf)
{
//=====================
num=huruf-65;
// Display 26 alphabets

for (repeat=0; repeat<100; repeat++)
{
column = 1;
for(count = num*5;count < (num*5+6);count++) //num=0,5,10,15,dst…
{
PORTB = ~Alphabets[count];
PORTA = column;
delay_ms(5);
column = column<<1;
}
}
delay_ms(10);

//=====================
}

Ebook pengetahuan Dasar RS485

 

Ebook pengetahuan Dasar RS485 bisa di download disini

https://drive.google.com/file/d/0BzD886yEhaFrUTVOYmRlQjNCYlE/view?usp=sharing

Contoh Code C Microcontroller AVR Membaca String Barcode Scanner

/*****************************************************
Date : 7/27/2015
Chip type : ATmega16
Clock frequency : 11.059200 MHz
*****************************************************/

#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#asm
//.equ __lcd_port=0x15 ;PORTC
//.equ __lcd_port=0x15 ;PORTC
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
#define PANJANGBARCODE 10

char barislcd=0;
unsigned int REGISTERS[50];
unsigned char data_in[15];
unsigned char databaca[15];
unsigned char data_count;
unsigned char ada_data;
unsigned int QtyOutput;
char lcd[25];
unsigned char indexarray=0;
char temdataArray[10][11];
//char balasan[]=”C=250″;
// Variables to hold current settings

void simpandiarray( char data[],unsigned char indek);
void bacaarray(char data[], char indek);
void process_command();
void simpankeregister(char strData[], unsigned char tempAddr) ;
// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
data_in[data_count] = UDR;

// End of line!
if (data_in[data_count] == ‘\r’) // end of frame: ‘\n’ ‘\r’
{
data_in[data_count-1]=0x00; //data_in[] dijadikan string tambah 0x00 di akhir

if(data_count==12)
{
process_command() ;
}
else {
lcd_gotoxy(0,2);
lcd_putsf(“data eror “);
}
//clear_data_in();
data_count = 0;
return;
}
else
{
data_count++;
}
//============

}
// USART Transmitter buffer
#define TX_BUFFER_SIZE 8
char tx_buffer[TX_BUFFER_SIZE];
unsigned char tx_index,tx_counter;
// USART Transmitter interrupt service routine
interrupt [USART_TXC] void usart_tx_isr(void)
{
if (tx_counter)
{
–tx_counter;
UDR=tx_buffer[tx_index];
if (++tx_index ==8) tx_index=0;
};
}
void process_command()
{
char i,j,k,m;
//a b c d e f g h i j
//0 1 2 3 4 5 6 7 8 9
QtyOutput++ ;
delay_ms(50);
lcd_gotoxy(13,3);
itoa(QtyOutput,lcd);
lcd_puts(lcd);

simpandiarray(data_in,indexarray) ;

//display
bacaarray(databaca,indexarray);

lcd_gotoxy(0,barislcd);
lcd_puts(databaca);
delay_ms(50);
if(barislcd == 0){
lcd_gotoxy(11,barislcd+3);
lcd_putchar(0x20);
}
//=======================
if(barislcd > 0){
lcd_gotoxy(11,barislcd-1);
lcd_putchar(0x20);
}
lcd_gotoxy(11,barislcd);
lcd_putsf(“*”);
delay_ms(50);
//=======================

barislcd++;
if(barislcd==4) {
barislcd=0;
}

delay_ms(50);
lcd_gotoxy(13,2);
itoa(indexarray*5,lcd);
lcd_puts(lcd);

if(indexarray==9) {
indexarray=0;
lcd_gotoxy(13,2);
lcd_putchar(0x20);
lcd_gotoxy(14,2);
lcd_putchar(0x20);
lcd_gotoxy(13,2);
itoa(indexarray*5,lcd);
lcd_puts(lcd);
lcd_puts(lcd);
}
indexarray++;

}

void simpandiarray( char data[], unsigned char indek)
{
char i;
{
for(i=0;i<PANJANGBARCODE;i++)
temdataArray[indek,i]= data[i];
}
data[10]=0x00;
simpankeregister(data,(PANJANGBARCODE/2)*indek); // alamat 0,5,10,15,20

}

void bacaarray(char data[], char indek)
{
char i;
for(i=0;i<PANJANGBARCODE;i++){
data[i] =temdataArray[indek,i];
}
data[10]=0x00;
}
void main(void)
{

PORTA=0x00;
DDRA=0x00;

PORTB=0x00;
DDRB=0xff;

PORTC=0x00;
DDRC=0x00;

PORTD=0x37; //0011 0111
DDRD=0xc8; //1100 1000

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0xD8;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47; //9600
//UBRRL=0x0B; //57600
//UBRRL=0x05; // 115200
PORTD.3=0;
// LCD module initialization
lcd_init(16);

lcd_gotoxy(0,0);
lcd_putsf(“barcode buffer”);
delay_ms(1000);
lcd_clear();
// Global enable interrupts
#asm(“sei”)

while (1)
{

}
}
//=============function declaration ==========================

//simpan 1 string barcode ke 5 register ab cd ef gh ij
void simpankeregister(char strData[],unsigned char tempAddr)
{
char i;
unsigned int tempData=0;

for(i=0;i<PANJANGBARCODE/2;i++,tempAddr++)
{
tempData = strData[(i*2)];
tempData = tempData <<8;
tempData = tempData | strData[i*2+1]; //
REGISTERS[tempAddr] = tempData;
}
}

Contoh Program AVR Simulasi Modem Wavecom

untuk dasar AT Command bisa baca disini :

Beberapa  AT Command (dan respon modem)  yg sering digunakan antara lain

Dari AVR/PC Dari Modem keterangan…………………
AT <CR><LF>OK<CR><LF>  attention
ATE0 <CR><LF>OK<CR><LF>  Echo dimatikan
AT+CMGF=1 <CR><LF>OK<CR><LF>  set ke mode text
<CR><LF>+CGMI: “SM”,1<CR><LF>  interupsi/notif pemberitahuan ada sms baru
AT+CMGR=1 <CR><LF>+CMGR: “REC  READ ,” +6289661513602″ ,,”15/12/05,10:38: 19+28″ <CR><LF> <isi sms><CR><LF>OK<CR><LF>  baca sms indek no 1
AT+CMGL=”ALL”  +CMGL: 1,”REC READ”, “+6283840367773”,, “15/10/ 20,16:02: 28 + 28″ <isi sms> <CR><LF>OK<CR><LF>

+CMGL: 2,”REC READ”, “+628384036799”,, “15/10/ 20,16:02: 28 + 28” <isi sms> <CR><LF>OK<CR><LF>

list semua isi sms
AT+CMGD=2 <CR><LF>OK<CR><LF> hapus sms indek ke 2
AT+CMGS=<no hp> <CR><CTRL-Z>  <CR><LF>OK<CR><LF> kirim sms

Berikut ini contoh respon modem dalam bentuk text

<CR><LF>+CMGR: “REC READ”,”+6289661513602″,,”15/12/05,10:38:19+28″<CR><LF>
tes2 <CR><LF>OK<CR><LF>

Jika  kita convert per byte karakter nya dlm bentuk hexa menjadi sbb:

0D 0A 2B 43 4D 47 52 3A 20 22 52 45 43 20 52 45 41 44 22 2C 22 2B 36 32 38 39 36 36 31 35 31 33
36 30 32 22 2C 2C 22 31 35 2F 31 32 2F 30 35 2C 31 30 3A 33 38 3A 31 39 2B 32 38 22 0D 0A 74 65
73 32 0D 0A 0D 0A 4F 4B 0D 0A


Silahkan di lanjutkan ya…

smsmodemwavecom

 

/*****************************************************
Chip type : ATmega16
Clock frequency : 11,059200 MHz

program AVR pura pura jadi modem

*****************************************************/

#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
// .equ __lcd_port=0x18 ;PORTB
// .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

void process_command();
unsigned int parsing_data();
char compare(char *str1, char *str2);

unsigned int REGISTERS[15];
unsigned char data_in[16],alamatSlave;
unsigned char data_count;
unsigned char ada_data;

char lcd[25],dataString[20], dataChar,adaAwalPaket;
char alamatTemp[5],alamat;
char ok[]=”\r\nOK\r\n”;
char sms[]=”\r\n+CMGR: \”REC UNREAD\”,\”+6289661513602\”,\”98/10/01,18 :22 :11+00\”,\r\nrelay#01#ON\r\n” ;
//=====================================
char AT[]=”AT”;
char ATE0[]=”ATE0″;
char ATCMGF[]=”AT+CMGF=1″;
char ATCMGD[]=”AT+CMGD=1″ ;
char ATCMGR[]=”AT+CMGR=1″ ;
char ATCMGS[]=”AT+CMGS=1″ ;
char error[]=”\r\nerror\r\n”;

//ceritanya kalau tombol di tekan ada sms masukkirim notif +CMTI ke AVR
interrupt [EXT_INT0] void ext_int0_isr(void)
{
delay_ms(60);
putchar(‘+’);
putsf(“CMTI : \”SM\”,1″);
delay_ms(60);
}

// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
dataChar=UDR;

if(adaAwalPaket==0)
{
adaAwalPaket=1;
data_count=0;
}

if(adaAwalPaket==1) //karakter setelah @ disimpan
{
data_in[data_count] = dataChar;

if (data_in[data_count] == ‘\n’) // jika data batas akhir ‘\n’ simpan paket data sbg string
{
data_in[data_count]=0x00; //akhir sebuah string adalah byte 0x00 (NULL)
adaAwalPaket=0;
ada_data = 1;
data_count = 0;
lcd_gotoxy(0,0);
lcd_puts(data_in);
return;
}
else //data blm sampe ‘\n’
{
data_count++;
}
//============
}

}

// Declare your global variables here

void main(void)
{
PORTD=0x04;
DDRD=0x00;
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x98;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

// INT0: On
// INT0 Mode: Low level
GICR|=0x40;
MCUCR=0x00;
MCUCSR=0x00;
GIFR=0x40;

// LCD module initialization
lcd_init(16);

// Global enable interrupts
#asm(“sei”)

while (1)
{
// Place your code here
if(ada_data) // not null
{
process_command() ;
ada_data = 0;
};

};// eof while
} //eof main
unsigned int parsing_data()
{

return 0;
}

char compare(char *str1, char *str2)
{
if(!strcmp(str1,str2)){
return 1; }
else {
return 0;}
}

void process_command()
{

if(compare(data_in,AT))
{
puts(ok);
return ;
}
if(compare(data_in,ATE0))
{
lcd_gotoxy(0,1);
lcd_putsf(“minta echo off”);
puts(ok);
return ;
}

if(compare(data_in,ATCMGF))
{
lcd_gotoxy(0,1);
lcd_putsf(“minta MODE TEX”);
puts(ok);
return ;
}

if(compare(data_in,ATCMGR))
{
lcd_gotoxy(0,1);
lcd_putsf(“minta data sms”);
puts(sms);
puts(ok);
return ;
}

puts(error);

return;
}

Pengetahuan Dasar Pemrograman Sensor Berat ( Load Cell)

UNDER CONTRUCTION

Pendahulian

Sensor->IC HX711 -> Microcontroller -> Display

Sensor

Salah satu sensor berat (load cell ) yaitu Strain Gauge

Rangkaian Brigdge Stone

rangkaian ini digunakan untuk menambah sensitifitas output sensor

Serial Interface IC  HX711

IC HX711  adalah IC ADC 24 bit dgn output serial digital ,keluaran IC ini  berupa tegangan yg sebanding dengan berat yg di berikan.

HX711_OUT

Mencari peramaan linierisasi input Vs Output   (pers Y= aX + C).

karena input dan output tdk 100% linier maka perlu dicari persamaan untuk linierisasi hubungan input vs output.

Ambil data percobaan  berat dan Output Sensor

masukan tabel input vs output ke excel ->blok data tsb-> buat grafik scatter->klik kanan data di grafik -> add trenline->check add equationon chart.

misal  kita dapat persamaan Y=m.X – c    ,   Y adalah output ADC ,m =gradient/kemiringan ,  X = berat beban  , c =konstanta/offset

maka rumus mencari berat X = (Y-c)/m

code program membaca serial data IC HX711

misal dari beberapa data yg kita ambil kita dapatkan hubungan peramaan Y=0.5 X-600

Maka X= (Y-600)/0.5

 

#define  pin_data PORTB.0

#define pin_clock PORTB.1
unsigned long ReadCount(void){
unsigned long Count;
unsigned char i;

unigned long HX711_Buffer = 0;
unsigned long Weight= 0;
pin_data=1;
pin_clock=0;
Count=0;
while(pin_data);
for (i=0;i<24;i++){
pin_clock=1;
Count=Count<<1;
pin_clock=0;
if(pin_data) Count++;
}
pin_clock=1;
Count=Count^0x800000;
pin_clock=0;
return(Count);
}

unsigned int  GetWeight()
{
HX711_Buffer = ReadCount();
HX711_Buffer = HX711_Buffer/100;

Weight = HX711_Buffer;
Weight = Weight – 600;
Weight = (unsigned int)((float)Weight/0.5);

return Weight;
}

void main(void)

{

PORTB=0x01;
DDRB=0x02;

while(1)

{

// output ADC ic hx711 = readCount();

//berat=GetWeight();

}

referensi:

-datasheet HX711

-https://www.transducertechniques.com/wheatstone-bridge.aspx

-https://learn.sparkfun.com/tutorials/getting-started-with-load-cells

Pengetahuan Dasar Membuat menu Pilihan dan input data pada LCD 20×4 dan Keypad 4×4

menudengankeypad

rangkaian

menuutama

flowchart

kalkulator_avr

Rangkaian

Flowchart

Penjelasan

Code Program

penjelasan  selengkapnya ada di DVD tutorial