Embedtronix Build Your Embedded System

Tampilkan postingan dengan label Application Notes. Tampilkan semua postingan
Tampilkan postingan dengan label Application Notes. Tampilkan semua postingan

This example shows how to use a low-cost SIM800l GSM/GPS Module to send an SMS message in response to a security switch opening or closing.

Your need the following :
1 x SIM800l Module
1 x 3A Power Supply
1 x High Power Buck-to-Buck Converter
1 x Window/Door Switch
1 x Arduino Uno
1 x SIM card that supports a 2G network. 
Optional: USB Breakout

1. Power Supply
Remove the USB plug from the power supply (or optionally use the USB breakout to avoid removing the USB connector) and connect to the input of the buck-tobuck converter being mindful of polarity. Adjust the buck-to-buck converter for an output of approximately 4V. Actual value can be anywhere from 3.7V to 4.2V for the Sim800l module.
Connect the power from the buck-to-buck converter to the SIM800l VCC and GND connections.

2. SIM800l and Arduino
Connect Arduino GND and GND on the SIM800l module. It is important that this GND is common with the GND of the back-to-buck converter as the reference voltage must be the same.
Connect RXD and TXD to pins 10 and 11 on the Arduino Uno.

3. Window/Door switch. 
Connect one end of the door switch to Arduino digital pin 3. Connect the other end to GND. We are not going to short 5V to GND as we are going to use the internal pullup resistor on pin 3 to hold it high by default.

4. SIM Card
Setup your Ting account and insert the SIM (mini size - the Ting comes in macro size and can be broken into Mini or micro).

5. Arduino Libraries
Download this SIM800l Arduino library. There are many other libraries you can try but this will work fine for this example. Install it as a Zip library in the Arduino IDE.
Install Debounce2 library in the Arduino IDE. This is a known library, no need to download it, the system will do that automatically.

6. Arduino Sketch
Use this sketch, changing the phone number to the one you want to send an SMS message to.



/* this library is written by Cristian Steib.
* steibkhriz@gmail.com
* Designed to work with the GSM Sim800l, may work with SIM900L
*
* This library uses SoftwareSerial, you can define de RX and TX pin
* in the header "Sim800l.h" ,by default the pin is RX=10 TX=11..
* be sure that GND is attached to arduino too.
*
* RESET_PIN is optional for most usage
*
* Esta libreria usa SoftwareSerial, se pueden cambiar los pines de RX y TX
* en el archivo header, "Sim800l.h", por defecto los pines vienen configurado en
* RX=10 TX=11.
* Tambien se puede cambiar el RESET_PIN por otro que prefiera
*
* PINOUT:
* _____________________________
* | ARDUINO UNO >>> SIM800L |
* -----------------------------
* GND >>> GND
* RX 10 >>> TX
* TX 11 >>> RX
* RESET 2 >>> RST (optional)
* 
* POWER SOURCE 4.2V >>> VCC
*
* Created on: April 20, 2016
* Author: Cristian Steib
*
*/
#include <Sim800l.h>
#include <Bounce2.h>
#include <SoftwareSerial.h> //is necesary for the library!!

Sim800l Sim800l; //to declare the library
char* closedText;
char * openText;
char* number;
bool error; //to catch the response of sendSms

#define SWITCH_PIN 3 // Connect switch pin here
Bounce debouncer = Bounce();
int currentState = -1;
int lastState = -1;

void setup(){
 Serial.begin(9600);
 Sim800l.begin(); // initializate the library.
 closedText="Door has been closed"; //text for the message.
 openText="Door has been opened"; //text for the message.
 number="xxxxxxxxxx"; //sms phone number
 pinMode(SWITCH_PIN, INPUT_PULLUP);
 debouncer.attach(SWITCH_PIN);
 debouncer.interval(100);
 //digitalWrite(BUTTON_PIN, HIGH);
}

void loop(){
 debouncer.update();
 currentState = debouncer.read();
 if (currentState != lastState){
  if(currentState == HIGH){
   Serial.println("open");
   error=Sim800l.sendSms(number,openText);
  }
  else {
   error=Sim800l.sendSms(number,closedText);
   Serial.println("closed");
  }
  lastState = currentState;
 }
} 

Melanjutkan posting sebelumnya mengenai interfacing matrix keypad dengan mikrokotroler, posting kali ini adalah aplikasi dari Keypad 3x4 dan LCd 16x2 yang dihubungkan dengan board Sasakala-M32. Ilustrasi rangkaiannya adalah sebagai berikut :

klik disini untuk memperbesar gambar.

Skematik serta simulasi untuk aplikasi ini pada program Proteus adalah sebagai berikut :

image

Contoh kode programnya :

/*
== Sasakala-M32 - Keypad Demo ==
============================================
Project : Keypad - LCD

Hardware:
--------
- [Sasakala-M32 Board]
- LCD 16x2
- Resistor 470R
- Diode 1N4148
- Matrix Keypad 3x4

LCD Connection :
--------------
VSS -> GND
VDD -> +5V
VEE -> Anoda Diode 1N4148 (Katoda -> GND)

RS -> PA0
RW -> PA1
E -> PA2

DB0..DB3 -> N/C

DB4 -> PA4
DB5 -> PA5
DB6 -> PA6
DB7 -> PA7

LED+ -> +5V (via RES 100ohm)
LED- -> GND

KEYPAD Connection :
-----------------
COL1 -> PB6
COL2 -> PB5
COL3 -> PB4

ROW1 -> PB3
ROW2 -> PB2
ROW3 -> PB1
ROW4 -> PB0

============================================
Embedtronix (C)201011
*/
#include <avr/io.h>
#include <util/delay.h>

#define LDP PORTA //LCD Data Port
#define LCP PORTA //LCD Control pins
#define LDDR DDRA //direction register for LCD data port
#define LCDR DDRA //direction register for LCD control pins
#define LCD_RS 0 //pin LCD RS
#define LCD_RW 1 //pin LCD R/W
#define LCD_E 2 //pin LCD E
#define LCD_D4 4 //pin LCD D3
#define LCD_D5 5 //pin LCD D4
#define LCD_D6 6 //pin LCD D5
#define LCD_D7 7 //pin LCD D6

#define LCD_CLR 0 //DB0: clear display
#define LCD_HOME 1 //DB1: return to home position
#define LCD_CGRAM 6 //DB6: set CG RAM address
#define LCD_DDRAM 7 //DB7: set DD RAM address

// cursor position to DDRAM mapping
#define LCD_LINE0_DDRAMADDR 0x00
#define LCD_LINE1_DDRAMADDR 0x40
#define LCD_LINE2_DDRAMADDR 0x14
#define LCD_LINE3_DDRAMADDR 0x54

//KEYPAD Connection
#define KEYPAD_PORT PORTB
#define KEYPAD_DDR DDRB
#define KEYPAD_PIN PINB

//=========================================================
void LCDsendChar(uint8_t ch) //Sends Char to LCD
{
LDP=(ch&0b11110000);
LCP|=1<<LCD_RS;
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
LCP&=~(1<<LCD_RS);
_delay_ms(1);
LDP=((ch&0b00001111)<<4);
LCP|=1<<LCD_RS;
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
LCP&=~(1<<LCD_RS);
_delay_ms(1);
}

//=========================================================
void LCDsendCommand(uint8_t cmd) //Sends Command to LCD
{
LDP=(cmd&0b11110000);
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
LDP=((cmd&0b00001111)<<4);
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
}

//=========================================================
void LCDinit(void)//Initializes LCD
{
_delay_ms(15);
LDP=0x00;
LCP=0x00;
LDDR|=1<<LCD_D7|1<<LCD_D6|1<<LCD_D5|1<<LCD_D4;
LCDR|=1<<LCD_E|1<<LCD_RW|1<<LCD_RS;
//---------one------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4; //4 bit mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//-----------two-----------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4; //4 bit mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//-------three-------------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|0<<LCD_D4; //4 bit mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//--------4 bit--dual line---------------
LCDsendCommand(0b00101000);
//-----increment address, invisible cursor shift------
LCDsendCommand(0b00001100);
LCDsendCommand(0b00001100);
}

//=========================================================
void LCDclr(void) //Clears LCD
{
LCDsendCommand(1<<LCD_CLR);
}

//=========================================================
void LCDhome(void) //LCD cursor home
{
LCDsendCommand(1<<LCD_HOME);
}

//=========================================================
void LCDWriteString(const char *msg)
{
while(*msg!='\0')
{
LCDsendChar(*msg);
msg++;
}
}

//===================================================================
void LCDWriteInt(int val,unsigned int field_length)
{
char str[5]={0,0,0,0,0};
int i=4,j=0;
while(val)
{
str[i]=val%10;
val=val/10;
i--;
}
if(field_length==-1)
while(str[j]==0) j++;
else
j=5-field_length;

if(val<0) LCDsendChar('-');
for(i=j;i<5;i++)
{
LCDsendChar(48+str[i]);
}
}

//=========================================================
void LCDGotoXY(uint8_t x, uint8_t y) //Cursor to X Y position
{
register uint8_t DDRAMAddr;
// remap lines into proper order
switch(y)
{
case 0: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; break;
case 1: DDRAMAddr = LCD_LINE1_DDRAMADDR+x; break;
case 2: DDRAMAddr = LCD_LINE2_DDRAMADDR+x; break;
case 3: DDRAMAddr = LCD_LINE3_DDRAMADDR+x; break;
default: DDRAMAddr = LCD_LINE0_DDRAMADDR+x;
}
// set data address
LCDsendCommand(1<<LCD_DDRAM | DDRAMAddr);

}

//=========================================================
void WritetoLCD(uint8_t x,uint8_t y,const char msg)
{
LCDGotoXY(x,y-1);
LCDWriteString(msg);
}

//=========================================================
void LCDWriteIntXY(uint8_t x,uint8_t y,uint8_t value,uint8_t FieldLength)
{
LCDGotoXY(x,y-1);
LCDWriteInt(value,FieldLength);
}

//=========================================================
void delay1s(void)
{
uint8_t i;
for(i=0;i<100;i++)
{
_delay_ms(10);
}
}

//==========================================
//Function return the keycode of keypressed
//on the Keypad. Keys are numbered as follows
//
// [00] [01] [02]
// [03] [04] [05]
// [06] [07] [08]
// [09] [10] [11]
//
//Return:
// Any number between 0-11 depending on
// keypressed.
//
// 255 (hex 0xFF) if NO keypressed.
//
//==========================================
uint8_t GetKeyPressed()
{
uint8_t Row,Col;

KEYPAD_PORT|= 0X0F;

for(Col=0;Col<3;Col++)
{
KEYPAD_DDR&=~(0X7F);

KEYPAD_DDR|=(0X40>>Col);
for(Row=0;Row<4;Row++)
{
if(!(KEYPAD_PIN & (0X08>>Row)))
{
return (Row*3+Col+1);
}
}
}
return 0XFF; //Indicate No keypressed
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main()
{
unsigned char key;

LCDinit(); //Initialize LCD module
LCDclr(); //Clear the screen
WritetoLCD(0,1,"[Sasakala Board]");
WritetoLCD(0,2,"Embedtronix.com");
delay1s(); //Wait
LCDclr(); //Clear the screen
WritetoLCD(0,1,"KeyNumber: "); //String on line 1
WritetoLCD(0,2,"KeyPress : "); //String on line 1

while(1)
{
key=GetKeyPressed();
if(key==0xFF) {WritetoLCD(11,1,"--");}
else {LCDWriteIntXY(11,1,key,2);}
switch(key)
{
case 0xFF: WritetoLCD(11,2,"-"); break;
case 10: WritetoLCD(11,2,"*"); break;
case 11: WritetoLCD(11,2,"0"); break;
case 12: WritetoLCD(11,2,"#"); break;
default: LCDWriteIntXY(11,2,key,1);
}
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



Penjelasannya:



Aplikasi ini akan membaca data dari keypad dan menampilkannya pada LCD. Data yang ditampilkan berupa nomor tombol yang ditekan dan karakter yang mewakilinya. Misalnya jika ditekan tombol nonor 5, maka pada LCD akan tampil : “KeyNumber : 05” – “ KeyPress : 5” dan jika tombol ‘#’ yang ditekan maka pada LCD akan tampil : “KeyNumber : 12” – “ KeyPress : #”.



LCDinit();                //Initialize LCD module
LCDclr(); //Clear the screen
WritetoLCD(0,1,"[Sasakala Board]");
WritetoLCD(0,2,"Embedtronix.com");
delay1s(); //Wait
LCDclr(); //Clear the screen
WritetoLCD(0,1,"KeyNumber: "); //String on line 1
WritetoLCD(0,2,"KeyPress : "); //String on line 1



Pertama, program akan memanggil rutin untuk inisialisasi LCD (selengkapnya baca Interfacing LCD dengan mikrokontroler Bagian-3), kemudian tampilan LCD akan dibersihkan (clear), lalu akan ditampilkan tittle image



Gambar 1. Judul Project imageGambar 2. Tampilan saat tidak ada tombol yang ditekan imageGambar 3. Tampilan saat tombol no 2 ditekan



while(1)
{
key=GetKeyPressed();
if(key==0xFF)
{
LCDGotoXY(11,1); LCDsendChar('-');
LCDGotoXY(12,1); LCDsendChar('-');
}
else {LCDWriteIntXY(11,1,key,2);}
LCDGotoXY(11,2);
switch(key)
{
case 0xFF: LCDsendChar('-'); break;
case 10: LCDsendChar('*'); break;
case 11: LCDsendChar('0'); break;
case 12: LCDsendChar('#'); break;
default: LCDWriteIntXY(11,2,key,1);
}
}



Program utamanya adalah menampilkan nomor dan karakter tombol yang ditekan. Rutin ini akan berulang terus menerus. Jika tidak ada tombol yang ditekan, maka tampilan akan kembali seperti gambar 2 diatas.



Untuk koneksi LCD bisa diubah port-nya dengan cara menganti instruksi pada baris berikut, ganti PORTA, dan DDRA dengan port yang akan diganti.



#define LDP  PORTA    //LCD Data Port
#define LCP PORTA //LCD Control pins
#define LDDR DDRA //direction register for LCD data port
#define LCDR DDRA //direction register for LCD control pins



Sementara port untuk keypad bisa diubah pada baris



//KEYPAD Connection
#define KEYPAD_PORT PORTB
#define KEYPAD_DDR DDRB
#define KEYPAD_PIN PINB



Download project lengkapnya disini



Selamat Belajar !

Postingan kali ini akan membahas bagaimana mengintegrasikan Sasakal Board dengan sebuah LCD 16x2.
Konfigurasi rangkaiannya dapat dilihat pada gambar berikut
Klik disini untuk memperbesar gambar
Rutin programnya adalah sebagai berikut:
/*
    == AVR-Sasakala - Port I/O Demo ==
************************************************

Hardware:
    - [Sasakala-M32 Board]
    - LED 8x
     - Resistor 470R 8x

************************************************
        Embedtronix (C)201009
*/

#include <avr/io.h>
#include <util/delay.h>

#define LDP  PORTA    //LCD Data Port
#define LCP  PORTB    //LCD Control pins
#define LDDR DDRA    //direction register for LCD data port
#define LCDR DDRB    //direction register for LCD control pins
#define LCD_RS    0     //pin LCD RS
#define LCD_RW    1     //pin LCD R/W
#define LCD_E    2    //pin LCD E
#define LCD_D0    0    //pin LCD D0
#define LCD_D1    1    //pin LCD D1
#define LCD_D2    2    //pin LCD D1
#define LCD_D3    3    //pin LCD D2
#define LCD_D4    4    //pin LCD D3
#define LCD_D5    5    //pin LCD D4
#define LCD_D6    6    //pin LCD D5
#define LCD_D7    7    //pin LCD D6

#define LCD_CLR       0    //DB0: clear display
#define LCD_HOME      1    //DB1: return to home position
#define LCD_CGRAM     6    //DB6: set CG RAM address
#define LCD_DDRAM     7    //DB7: set DD RAM address

//#define LCDClear() LCDsendCommand(0b00000001)
//#define LCDHome() LCDsendCommand(0b00000010);

// cursor position to DDRAM mapping
#define LCD_LINE0_DDRAMADDR        0x00
#define LCD_LINE1_DDRAMADDR        0x40
#define LCD_LINE2_DDRAMADDR        0x14
#define LCD_LINE3_DDRAMADDR        0x54


//=========================================================
void LCDinit(void)//Initializes LCD
{
_delay_ms(15);
LDP=0x00;
LCP=0x00;
LDDR|=1<<LCD_D7|1<<LCD_D6|1<<LCD_D5|1<<LCD_D4|1<<LCD_D3
|1<<LCD_D2|1<<LCD_D1|1<<LCD_D0;
LCDR|=1<<LCD_E|1<<LCD_RW|1<<LCD_RS;
//---------one------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4|0<<LCD_D3
|0<<LCD_D2|0<<LCD_D1|0<<LCD_D0; //8 it mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;        
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//-----------two-----------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4|0<<LCD_D3
|0<<LCD_D2|0<<LCD_D1|0<<LCD_D0; //8 it mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;        
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//-------three-------------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4|0<<LCD_D3
|0<<LCD_D2|0<<LCD_D1|0<<LCD_D0; //8 it mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;        
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//--------8 bit dual line----------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4|1<<LCD_D3
|0<<LCD_D2|0<<LCD_D1|0<<LCD_D0; //8 it mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;        
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//-----increment address, cursor shift------
LDP=0<<LCD_D7|0<<LCD_D6|0<<LCD_D5|0<<LCD_D4|1<<LCD_D3
|1<<LCD_D2|1<<LCD_D1|0<<LCD_D0; //8 it mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;        
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(5);
}

//=========================================================
void LCDsendCommand(uint8_t cmd)    //Sends Command to LCD
{
LDP=cmd;
LCP|=1<<LCD_E;        
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);    
}

//=========================================================
void LCDsendChar(uint8_t ch)        //Sends Char to LCD
{
LDP=ch;
LCP|=1<<LCD_RS;
LCP|=1<<LCD_E;        
_delay_ms(1);
LCP&=~(1<<LCD_E);    
LCP&=~(1<<LCD_RS);
_delay_ms(1);
}

//=========================================================
void LCDclr(void)                    //Clears LCD
{
LCDsendCommand(1<<LCD_CLR);
}

//=========================================================
void LCDhome(void)            //LCD cursor home
{
LCDsendCommand(1<<LCD_HOME);
}

//=========================================================
void LCDWriteString(const char *msg)
{
while(*msg!='\0')
{
LCDsendChar(*msg);
msg++;
}
}

//===================================================================
void LCDWriteInt(int val,unsigned int field_length)
{
char str[5]={0,0,0,0,0};
int i=4,j=0;
while(val)
{
str[i]=val%10;
val=val/10;
i--;
}
if(field_length==-1)
while(str[j]==0) j++;
else
j=5-field_length;

if(val<0) LCDsendChar('-');
for(i=j;i<5;i++)
{
LCDsendChar(48+str[i]);
}
}

//=========================================================
void LCDGotoXY(uint8_t x, uint8_t y)    //Cursor to X Y position
{
register uint8_t DDRAMAddr;
// remap lines into proper order
switch(y)
{
case 0: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; break;
case 1: DDRAMAddr = LCD_LINE1_DDRAMADDR+x; break;
case 2: DDRAMAddr = LCD_LINE2_DDRAMADDR+x; break;
case 3: DDRAMAddr = LCD_LINE3_DDRAMADDR+x; break;
default: DDRAMAddr = LCD_LINE0_DDRAMADDR+x;
}
// set data address
LCDsendCommand(1<<LCD_DDRAM | DDRAMAddr);

}

//=========================================================
void WritetoLCD(x,y,msg) 
{
LCDGotoXY(x,y-1);
LCDWriteString(msg);
}

//=========================================================
void LCDWriteIntXY(x,y,value,FieldLength) 
{
LCDGotoXY(x,y-1);
LCDWriteInt(value,FieldLength);
}

//=========================================================
void delay1s(void)
{
uint8_t i;
for(i=0;i<100;i++)
{
_delay_ms(10);
}
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void main()
{
unsigned char i;

LCDinit();                    //Initialize LCD module

while(1)
{

LCDclr();                    //Clear the screen

WritetoLCD(0,1,"[Sasakala Board]");
WritetoLCD(0,2,"Embedtronix.com");
delay1s();                    //Wait

LCDclr();                            //Clear the screen
WritetoLCD(0,1,"Waiting... ");        //String on line 1
WritetoLCD(0,2,"Loading ");            //String on line 2

//Print some numbers
for (i=0;i<99;i+=1)
{
LCDWriteIntXY(9,2,i,2);
WritetoLCD(11,2,"%");
_delay_loop_2(0);    
_delay_loop_2(0);    
//_delay_loop_2(0);    
//_delay_loop_2(0);    
}

LCDclr();                            //Clear the screen
WritetoLCD(0,1,"SasakalaLCD Demo");
WritetoLCD(3,2,"Mode 8-bit");
delay1s();                    //Wait
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



Sebelum mencobanya langsung pada Sasakala Board, kita coba dulu membuat simulasinya di Proteus. Berikut rangkaian dan screenshot pada saat simulasi di Proteus





Setelah sukses baru kita coba langsung ke Sasakala board


Selamat mencoba !


Download Sasakala-LCD-8bit dalam project AVR Studio lengkap dengan simulasi Proteus

Sasakala Board-M32 telah disertai dengan built-in default application, berupa aplikasi Running LED serta aplikasi Serial RS232 Terminal.

Untuk mencoba aplikasi Running LED, terlebih dahulu harus dipersiapkan komponen tambahan berupa 8 buah LED dan 8 buah resistor 470 ohm disamping breadboard dan kabel jumpernya.

Konfigurasi rangkaiannya adalah sebagai berikut :

Klik disini untuk memperbesar gambar

Jika ingin mengubah tampilan, berikut kode programnya:

/*
== AVR-Sasakala - Port I/O Demo ==
************************************************

Hardware:
- [Sasakala-M32 Board]
- LED 8x
- Resistor 470R 8x

************************************************
Embedtronix (C)201009
*/

#include <avr io.h>
#include <inttypes.h>
#include <util delay.h>


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

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

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

// Port D initialization
PORTD=0x0F; // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
DDRD=0xFF; // State7=0 State6=0 State5=0 State4=0 State3=1 State2=1 State1=1 State0=1
}

void main()
{

InitPort();

while(1)
{
unsigned char j; // LED var

for (j=0x01; j< 0x80; j<<=1)
{ // Blink LED 0,1,2,3,4,5,6
PORTA = j; // Output to LED Port
PORTB = j; // Output to LED Port
PORTC = j; // Output to LED Port
PORTD = j; // Output to LED Port
_delay_ms(750); // Delay for 750 Counts
}

for (j=0x80; j> 0x01; j>>=1)
{ // Blink LED 6,5,4,3,2,1,0
PORTD = j; // Output to LED Port
PORTB = j; // Output to LED Port
PORTC = j; // Output to LED Port
PORTD = j; // Output to LED Port
_delay_ms(750); // call wait function
}
}


Download Source Code



Selamat mencoba ..!

author
Embedtronix
Build Your Embedded System. Belajar bareng ngoprek Microcontroller, Arduino, TPLink, GLiNet dan ilmu Microelectronic lainnya.