Anda di halaman 1dari 4

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

This program was produced by the


CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date
: 12/9/2011
Author :
Company :
Comments:
Chip type
: ATmega8535
Program type
: Application
AVR Core Clock frequency: 4.000000 MHz
Memory model
: Small
External RAM size
: 0
Data Stack size
: 128
*****************************************************/
#include
#include
#include
#include
#include

<mega8535.h>
<stdio.h>
<stdlib.h>
<delay.h>
<math.h>

/
#define
#define
#define
#define

kol1
kol2
kol3
kol4

PINB.4
PINB.5
PINB.6
PINB.7

void scan_keypad() //penekanan keypad kemudian ditampilkan di LCD


{
PORTB = 0b11111110;
delay_ms(30);
if (kol1 == 0) {delay_ms(25);
8"); OCR2=28; delay_ms(25); } //1
if (kol2 == 0) {delay_ms(25);
6"); OCR2=56; delay_ms(25); } //2
if (kol3 == 0) {delay_ms(25);
4"); OCR2=84; delay_ms(25); } //3
if (kol4 == 0) {delay_ms(25);
0"); OCR2=50; delay_ms(25); } //A

lcd_clear(); lcd_gotoxy(0,1); lcd_putsf("OCR=2


lcd_clear(); lcd_gotoxy(0,1); lcd_putsf("OCR=5
lcd_clear(); lcd_gotoxy(0,1); lcd_putsf("OCR=8
lcd_clear(); lcd_gotoxy(0,1); lcd_putsf("OCR=5

PORTB = 0b11111101;
delay_ms(30);
if (kol1 == 0) {delay_ms(25); lcd_clear();
12"); OCR2=112; delay_ms(25); } //4
if (kol2 == 0) {delay_ms(25); lcd_clear();
40"); OCR2=140; delay_ms(25); } //5
if (kol3 == 0) {delay_ms(25); lcd_clear();
68"); OCR2=168; delay_ms(25); } //6
if (kol4 == 0) {delay_ms(25); lcd_clear();
00"); OCR2=100; delay_ms(25); } //B

lcd_gotoxy(0,1); lcd_putsf("OCR=1
lcd_gotoxy(0,1); lcd_putsf("OCR=1
lcd_gotoxy(0,1); lcd_putsf("OCR=1
lcd_gotoxy(0,1); lcd_putsf("OCR=1

PORTB = 0b11111011;
delay_ms(30);
if (kol1 == 0) {delay_ms(25); lcd_clear();
96"); OCR2=196; delay_ms(25); } //7
if (kol2 == 0) {delay_ms(25); lcd_clear();
24"); OCR2=224; delay_ms(25); } //8
if (kol3 == 0) {delay_ms(25); lcd_clear();
52"); OCR2=252; delay_ms(25); } //9
if (kol4 == 0) {delay_ms(25); lcd_clear();
00"); OCR2=200; delay_ms(25); } //C

lcd_gotoxy(0,1); lcd_putsf("OCR=1
lcd_gotoxy(0,1); lcd_putsf("OCR=2
lcd_gotoxy(0,1); lcd_putsf("OCR=2
lcd_gotoxy(0,1); lcd_putsf("OCR=2

PORTB = 0b11110111;
delay_ms(30);
if (kol1 == 0) {delay_ms(25); lcd_clear(); lcd_gotoxy(0,1); lcd_putsf("CHANG
E LED"); delay_ms(1000); lcd_clear(); indeks=1; PORTD.6=1; } //*
if (kol2 == 0) {delay_ms(25); lcd_clear(); lcd_gotoxy(0,1); lcd_putsf("OCR=
0");
OCR2=0; delay_ms(25); } //0
if (kol3 == 0) {delay_ms(25); lcd_clear(); lcd_gotoxy(0,1); lcd_putsf("CHANG
E LED"); delay_ms(1000); lcd_clear(); indeks=0; PORTD.6=0; } //#
if (kol4 == 0) {delay_ms(25); lcd_clear(); lcd_gotoxy(0,1); lcd_putsf("OCR=
255"); OCR2=255; delay_ms(25); } //D
}
void idks()
{
if (indeks==0)
{
lcd_gotoxy(13,1);
lcd_putsf("2X2");
}
if (indeks>=1)
{
indeks=1;
lcd_gotoxy(13,1);
lcd_putsf("6X6");
}
}
void main(void)
{
PORTA=0x00;
DDRA=0x00;
PORTB=0xFF;
DDRB=0x0F;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0xC0;
//
//
//
//
//

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: 500.000 kHz
// Mode: Fast PWM top=0xFF
// OC2 output: Non-Inverted PWM
ASSR=0x00;
TCCR2=0x6A;
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 Clock frequency: 31.250 kHz
// ADC Voltage Reference: AVCC pin

// ADC High Speed Mode: Off


// ADC Auto Trigger Source: ADC Stopped
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x87;
SFIOR&=0xEF;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Alphanumeric LCD initialization
// Connections specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 4
// D5 - PORTC Bit 5
// D6 - PORTC Bit 6
// D7 - PORTC Bit 7
// Characters/line: 16
lcd_init(16);
while (1)
{
idks();
baca_lux();
scan_keypad();
}
}

Anda mungkin juga menyukai