Lompat ke konten Lompat ke sidebar Lompat ke footer

Membuat Program Target dan counter output Produksi

Yang kita butuhkan, yaitu :

- Compiler :CodeVision
- Microcontroller : ATmega8535
-Port C  dipasang display LCD 2×16
-PortD  pin 2,3,4,5,dan pin 6 sbg input switch/sensor.
-PortB pin 0dan 1 sebagai input switch On Off Timer 0 dan Timer1
Gambar Rangkaian:
Program selengkapnya:
/****************************************************
This program was produced by the
CodeWizardAVR V2.05
Automatic Program Generator
Chip type           : ATmega8535
Program type        : Application
Clock frequency     : 4.000000 MHz
*****************************************************/
#include <mega8535.h>
#include <lcd.h>
#include <delay.h>
#include <stdio.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0×15 ;PORTC
#endasm
int waktu_kerja;
unsigned int count=0,output;
unsigned int target=0;
int cycle=1;
int bal=0;
unsigned int cycle_ms;
char tampung[10];
char tampung2[10];
char tampung3[10];
char tampung4[10];
char tampung5[10];
// variable di eeprom
unsigned long int eeprom*pointer_output;
unsigned long int eeprom*pointer_target;
unsigned long int eeprom*pointer_cycle;
unsigned long int eeprom*pointer_waktu_kerja;
// Timer 0 (dilaksanakan tiap 10 ms)
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
TCNT0=0xD9;
// Place your code here
count=count+1;
cycle_ms = cycle * 100;         // 1 cycle x 100 loop x 10 ms = 1000 ms (1 detik)
if(count==cycle_ms)
{
target =target+1;
*pointer_target=target;
count=0;
}
}
// Timer 1 ( dilaksanakan tiap 1 detik)
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer 1 value
TCNT1H=0x0B;
TCNT1L=0xB8;
// Place your code here
waktu_kerja = waktu_kerja + 1;
*pointer_waktu_kerja=waktu_kerja;
}
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=0×00;
DDRA=0×00;
// 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=0×00;
DDRB=0×00;
// 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=0×00;
DDRC=0×00;
// 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=0×00;
DDRD=0×00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 3.906 kHz
// Mode:Normaltop=FFh
// OC0 output: Disconnected
TCCR0=0×05;
TCNT0=0xD9;
OCR0=0×00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 62.500 kHz
// Mode:Normaltop=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0×00;
TCCR1B=0×03;
TCNT1H=0x0B;
TCNT1L=0xB8;
ICR1H=0×00;
ICR1L=0×00;
OCR1AH=0×00;
OCR1AL=0×00;
OCR1BH=0×00;
OCR1BL=0×00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0×05;
// LCD module initialization
lcd_init(16);
output=*pointer_output;
target=*pointer_target;
cycle= *pointer_cycle ;
waktu_kerja = *pointer_waktu_kerja;
// LCD module initialization
lcd_init(16);
// tampilan awal
lcd_gotoxy(0,0);
lcd_putsf(“Ref:    out:”);
lcd_gotoxy(0,1);
lcd_putsf(“bal:    tak:   s”);
// Global enable interrupts
#asm(“sei”)
while (1)
{
// Place your code here
//==========================//
// timer off  (rest time)   //
//==========================//
if (!PINB.0)
{
delay_ms(100);
TIMSK=0×00;  //matikan timer0 dan timer1
meneh0:
if (!PINB.0)
{goto meneh0;}
delay_ms(100);
} //=================================
//====================================//
// timer on   (masuk stlh  rest time) //
//====================================//
if (!PINB.1)
{
delay_ms(100);
TIMSK=0×05;
meneh1:
if (!PINB.1)
{goto meneh1;}
delay_ms(100);
}
//==========================//
//      output -1           //
//==========================//
if (!PIND.2)
{
delay_ms(100);
output–;
*pointer_output=output;
meneh2:
if (!PIND.2)
{goto meneh2;}
delay_ms(100);
}
//==========================//
//     output +1            //
//==========================//
if (!PIND.3)
{
delay_ms(100);
output++;
*pointer_output=output;
meneh3:
if (!PIND.3)
{goto meneh3;}
delay_ms(100);
}
//==========================//
//     cycletime + 1        //
//==========================//
if (!PIND.4)
{
delay_ms(100);
cycle++;
*pointer_cycle=cycle;
delay_ms(90);
meneh4:
if (!PIND.4)
{goto meneh4;}
delay_ms(100);
}
//======================================================//
// reset output, target & tampilkan work time 5 detik   //
//======================================================//
if (!PIND.5)
{
delay_ms(100);
output=0;
target=0;
*pointer_output=output;
delay_ms(90);
*pointer_target = target;
delay_ms(90);
meneh5:
if (!PIND.5)
{goto meneh5;}
delay_ms(100);
//mtampilkan work time 5 detik
lcd_gotoxy(0,0);
lcd_putsf(“wk :”);
sprintf(tampung5,”%i “,waktu_kerja);
lcd_gotoxy(4,0);
lcd_puts(tampung5);
delay_ms(5000);
waktu_kerja=0;
*pointer_waktu_kerja = waktu_kerja;
delay_ms(90);
}// end of reset
//==========================//
//       cycle – 1          //
//==========================//
if (!PIND.6)
{
delay_ms(100);
cycle–;
if(cycle<1)
{cycle=1;}
*pointer_cycle=cycle;
delay_ms(90);
meneh6:
if (!PIND.6)
{goto meneh6;}
delay_ms(100);
}
//==========================
sprintf(tampung,”%i “,target);
lcd_gotoxy(4,0);
lcd_puts(tampung);
delay_ms(100);
sprintf(tampung2,”%i “,output);
lcd_gotoxy(12,0);
lcd_puts(tampung2);
delay_ms(100);
bal=output-target;
sprintf(tampung3,”%i “,bal);
lcd_gotoxy(4,1);
lcd_puts(tampung3);
delay_ms(100);
sprintf(tampung4,”%i “,cycle);
lcd_gotoxy(12,1);
lcd_puts(tampung4);
//===============================
}; // end while(1)
}  // end of main()

Posting Komentar untuk "Membuat Program Target dan counter output Produksi"

Profit Blogger
INCOME BLOGGER