You are on page 1of 19

Tugas pak santoso

Print screen atas


Lanjut listing program

#include <mega8535.h>

#include <delay.h>
#include <stdlib.h>
// Alphanumeric LCD Module functions
#include <alcd.h>
int var1,var2,var3,var4,var5;
char temp[6];
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#define ADC_VREF_TYPE 0x00

// Read the AD conversion result


unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}

// Declare your global variables here

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=0x00;

// 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=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;

// 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 Clock frequency: 691.200 kHz
// ADC Voltage Reference: AREF pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: ADC Stopped
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
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);
lcd_clear();
while (1)
{
var1=read_adc(0);//baca ADC channel 0 (ADC0 atau PA0)
var4=(var1/16);
var5=(var4/16);
var3=(var4%16);

var2=(var1%16);
lcd_gotoxy(0,0);
lcd_putsf("tugas pak san");
itoa(var1,temp);//menampilkan nilai ADC0
lcd_gotoxy(0,1) ;
lcd_puts(temp);
lcd_putsf("Des");
if (var5>=10) {
switch (var5) {
case 10:
lcd_gotoxy(8,1);
lcd_putsf("A");
break;
case 11:
lcd_gotoxy(8,1);
lcd_putsf("B");
break;
case 12:
lcd_gotoxy(8,1);
lcd_putsf("C");
break;
case 13:
lcd_gotoxy(8,1);
lcd_putsf("D");
break;
case 14:

lcd_gotoxy(8,1);
lcd_putsf("E");
break;
case 15:
lcd_gotoxy(8,1);
lcd_putsf("F");
break;
}
}
else {
itoa(var5,temp);
lcd_gotoxy(8,1) ;
lcd_puts(temp);
}
if (var3>=10) {
switch (var3) {
case 10:
lcd_gotoxy(9,1);
lcd_putsf("A");
break;
case 11:
lcd_gotoxy(9,1);
lcd_putsf("B");
break;
case 12:
lcd_gotoxy(9,1);

lcd_putsf("C");
break;
case 13:
lcd_gotoxy(9,1);
lcd_putsf("D");
break;
case 14:
lcd_gotoxy(9,1);
lcd_putsf("E");
break;
case 15:
lcd_gotoxy(9,1);
lcd_putsf("F");
break;
}
}
else {
//var5=var3/10;
itoa(var3,temp);
lcd_gotoxy(9,1) ;
lcd_puts(temp);;
}
if (var2>=10) {
switch (var2) {
case 10:
lcd_gotoxy(10,1);

lcd_putsf("AH");
break;
case 11:
lcd_gotoxy(10,1);
lcd_putsf("BH");
break;
case 12:
lcd_gotoxy(10,1);
lcd_putsf("CH");
break;
case 13:
lcd_gotoxy(10,1);
lcd_putsf("DH");
break;
case 14:
lcd_gotoxy(10,1);
lcd_putsf("EH");
break;
case 15:
lcd_gotoxy(10,1);
lcd_putsf("FH");
break;
}
}
else {
//var5=var2/10;

itoa(var2,temp);
lcd_gotoxy(10,1) ;
lcd_puts(temp);
lcd_putchar('H');
//delay_ms(50);
}
}
}

#include <mega8535.h>
#include <delay.h>
// Declare your global variables here

void main(void)
{
while (1)

{
DDRA=0x01;
PORTA=0xff;
delay_ms(50);
PORTA=0xfe;
delay_ms(50);
};
}

void setup() {
// put your setup code here, to run once:
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(0,INPUT);
pinMode(1,INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
int var1=digitalRead(0);
int var2=digitalRead(1);
if (var1==LOW) {
digitalWrite(13,HIGH);
//digitalWrite(12,HIGH);
}else {
digitalWrite(13,LOW);
}
if (var2==LOW) {
//digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
}
else {
//digitalWrite(13,LOW);
digitalWrite(12,LOW);
}
}

void setup() {
// put your setup code here, to run once:
pinMode(0,INPUT);
pinMode(1,INPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
int var1 = 1;
int var2 = 1;
}

void loop() {
// put your main code here, to run repeatedly:
int var1 = digitalRead(0);

int var2 = digitalRead(1);


//digitalWrite(12,LOW);
//digitalWrite(13,LOW);
if ((var1==HIGH)&&(var2==HIGH)) {
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
}
else if ((var1==LOW)&&(var2==LOW)) {
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
}
else {
digitalWrite(12,LOW);
digitalWrite(13,LOW);
}
}

void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
int kecepatan=analogRead(A0)/4;
boolean nilai=1;
digitalWrite(13,nilai);
digitalWrite(12,!nilai);
analogWrite(11,kecepatan);
delay(2500);

digitalWrite(12,nilai);
digitalWrite(13,!nilai);
analogWrite(11,kecepatan);
delay(2500);
}

#include <mega8535.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <stdio.h>

void main(void)

{
lcd_init(16);
lcd_gotoxy(0,0);
lcd_putsf("TUGAS PAK SAN");
lcd_gotoxy(0,1);
lcd_putsf("tampil LCD");
}

You might also like