Anda di halaman 1dari 10

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

This program was produced by the


CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date
: 10/21/2013
Author : Sh.mukti
Company : Jangan gunakan software bajakan!
Comments:
Chip type
: ATmega16
Program type
: Application
AVR Core Clock frequency: 12.000000 MHz
Memory model
: Small
External RAM size
: 0
Data Stack size
: 256
*****************************************************/
#include <mega16.h>
#include <stdio.h>
#include <delay.h>
#define
#define
#define
#define
#define
#define
#define
#define

led1
led2
led3
led4
led5
led6
led7
led8

PORTD.0
PORTD.1
PORTD.2
PORTD.3
PORTD.4
PORTD.5
PORTD.6
PORTD.7

#define buzz PORTA.4


#define
#define
#define
#define
#define
#define
#define
#define

s8
s7
s6
s5
s4
s3
s2
s1

PINC.0
PINC.1
PINC.2
PINC.3
PINC.4
PINC.5
PINC.6
PINC.7

#define nyala 1
#define mati 0
int a;
// Alphanumeric LCD functions
#include <alcd.h>
// Declare your global variables here
void cepat()
{
unsigned char a,b;

lcd_gotoxy(0,0);
lcd_putsf("C");
lcd_gotoxy(1,0);
lcd_putsf("d");
lcd_gotoxy(2,0);
lcd_putsf("e");
lcd_gotoxy(0,1);
lcd_putsf("f");
led1=nyala;
}
void cekled()
{
lcd_gotoxy(0,0);
lcd_putsf("CEK LED1 NYALA");
led1=nyala;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED2 NYALA");
led2=nyala;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED3 NYALA");
led3=nyala;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED4 NYALA");
led4=nyala;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED5 NYALA");
led5=nyala;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED6 NYALA");
led6=nyala;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED7 NYALA");
led7=nyala;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED8 NYALA");
led8=nyala;
delay_ms(1000);
lcd_clear();

lcd_gotoxy(0,0);
lcd_putsf("CEK LED1 MATI");
led1=mati;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED2 MATI");
led2=mati;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED3 MATI");
led3=mati;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED4 MATI");
led4=mati;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED5 MATI");
led5=mati;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED6 MATI");
led6=mati;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED7 MATI");
led7=mati;
delay_ms(1000);
lcd_gotoxy(0,0);
lcd_putsf("CEK LED8 MATI");
led8=mati;
delay_ms(1000);
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SELESAI");
delay_ms(1000);
}
void ceksaklar()
{
saklar:
lcd_clear();
lcd_gotoxy(0,1);
lcd_putsf("TEKAN RESET-MENU");
delay_ms(100);
led1=led2=led3=led4=led5=led6=led7=led8=mati;
if(s1==0)
{
led1=nyala;
lcd_gotoxy(0,0);
lcd_putsf("SAKLAR 1");
delay_ms(100);
}

if(s2==0)
{
led2=nyala;
lcd_gotoxy(0,0);
lcd_putsf("SAKLAR 2");
delay_ms(100);
}
if(s3==0)
{
led3=nyala;
lcd_gotoxy(0,0);
lcd_putsf("SAKLAR 3");
delay_ms(100);
}
if(s4==0)
{
led4=nyala;
lcd_gotoxy(0,0);
lcd_putsf("SAKLAR 4");
delay_ms(100);
}
if(s5==0)
{
led5=nyala;
lcd_gotoxy(0,0);
lcd_putsf("SAKLAR 5");
delay_ms(100);
}
if(s6==0)
{
led6=nyala;
lcd_gotoxy(0,0);
lcd_putsf("SAKLAR 6");
delay_ms(100);
}
if(s7==0)
{
led7=nyala;
lcd_gotoxy(0,0);
lcd_putsf("SAKLAR 7");
delay_ms(100);
}
if(s8==0)
{
led8=nyala;
lcd_gotoxy(0,0);
lcd_putsf("SAKLAR 8");
delay_ms(100);
}
goto saklar;
}
void keypad()
{

delay_ms(1000);
keypadlagi:
lcd_gotoxy (0,1);
lcd_putsf ("TEKAN RESET-MENU");
DDRC = 0b00001111;
PORTC = 0b11111110;
delay_us(1);
if (PINC==0b11101110){
lcd_gotoxy (0,0);
lcd_putsf ("D");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b11011110){
lcd_gotoxy (0,0);
lcd_putsf ("C");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b10111110){
lcd_gotoxy (0,0);
lcd_putsf ("B");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b01111110){
lcd_gotoxy (0,0);
lcd_putsf ("A");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
};
//delay_ms(100);
DDRC = 0b00001111;
PORTC = 0b11111101;
delay_us(1);
if (PINC==0b11101101){
lcd_gotoxy (0,0);
lcd_putsf ("#");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b11011101){
lcd_gotoxy (0,0);
lcd_putsf ("9");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b10111101){
lcd_gotoxy (0,0);
lcd_putsf ("6");
delay_ms(100);
lcd_gotoxy (0,0);

lcd_putsf(" ");
}
else if (PINC==0b01111101){
lcd_gotoxy (0,0);
lcd_putsf ("3");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
};
//delay_ms(100);
DDRC = 0b00001111;
PORTC = 0b11111011;
delay_us(1);
if (PINC==0b11101011){
lcd_gotoxy (0,0);
lcd_putsf ("0");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b11011011){
lcd_gotoxy (0,0);
lcd_putsf ("8");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b10111011){
lcd_gotoxy (0,0);
lcd_putsf ("5");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b01111011){
lcd_gotoxy (0,0);
lcd_putsf ("2");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
};
//delay_ms(100);
DDRC = 0b00001111;
PORTC = 0b11110111;
delay_us(1);
if (PINC==0b11100111) {
lcd_gotoxy (0,0);
lcd_putsf ("*");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b11010111){
lcd_gotoxy (0,0);
lcd_putsf ("7");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b10110111){

lcd_gotoxy (0,0);
lcd_putsf ("4");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
}
else if (PINC==0b01110111){
lcd_gotoxy (0,0);
lcd_putsf ("1");
delay_ms(100);
lcd_gotoxy (0,0);
lcd_putsf(" ");
};
//delay_ms(100);
goto keypadlagi;
}
void ceklcd()
{
for(a=0;a<16;a++)
{
lcd_gotoxy(a,0);
lcd_putsf("#");
lcd_gotoxy(a,1);
lcd_putsf("#");
delay_ms(500);
lcd_clear();
}
}
void loading()
{
lcd_gotoxy(0,0);
lcd_putsf("Loading.");
buzz=nyala;
delay_ms(100);
lcd_gotoxy(0,0);
lcd_putsf("Loading..");
buzz=mati;
delay_ms(100);
lcd_gotoxy(0,0);
lcd_putsf("Loading...");
buzz=nyala;
delay_ms(100);
lcd_gotoxy(0,0);
lcd_putsf("Loading....");
buzz=mati;
delay_ms(100);
lcd_gotoxy(0,0);
lcd_putsf("Loading.....");
buzz=nyala;
delay_ms(100);
lcd_gotoxy(0,0);
lcd_putsf("Loading......");
buzz=mati;
delay_ms(100);
lcd_gotoxy(0,0);
lcd_putsf("Loading.......");
buzz=nyala;
delay_ms(100);

lcd_gotoxy(0,0);
lcd_putsf("Loading........");
buzz=mati;
delay_ms(100);
lcd_gotoxy(0,0);
lcd_putsf("Loading.........");
delay_ms(100);
lcd_clear();
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A 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
PORTA=0x00;
DDRA=0xFF;
// Port B 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
PORTB=0x00;
DDRB=0x00;
// 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=0xFF;
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=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;

TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
//
//
//
//
//
//
//
//

Alphanumeric LCD initialization


Connections are specified in the
Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
RS - PORTB Bit 0
RD - PORTB Bit 1
EN - PORTB Bit 2
D4 - PORTB Bit 4
D5 - PORTB Bit 5

// D6 - PORTB Bit 6
// D7 - PORTB Bit 7
// Characters/line: 16
lcd_init(16);
while (1)
{
// Place your code here
cepat();
}
}

Anda mungkin juga menyukai