SlideShare uma empresa Scribd logo
1 de 7
LAMPIRAN 1.PROGRAM ROBOT 
/********************************************* 
This program was produced by the 
CodeWizardAVR V1.24.0 Standard 
Automatic Program Generator 
© Copyright 1998-2003 HP InfoTech s.r.l. 
http://www.hpinfotech.ro 
e-mail:office@hpinfotech.ro 
Project : 
Version : 
Date : 17/11/2013 
Author : hendawan 
Company : 
Comments: 
Chip type : Atmega32 
Program type : Application 
Clock frequency : 12,000000 MHz 
Memory model : Small 
External SRAM size : 0 
Data Stack size : 128 
*********************************************/ 
#define SkiXX PIND.0 
#define SkiX PIND.1 
#define Ski PIND.2 
#define Ska PIND.3 
#define SkaX PIND.4 
#define SkaXX PIND.5
#define EnKi PORTC.4 
#define dirA_Ki PORTC.0 
#define dirB_Ki PORTC.1 
#define EnKa PORTC.5 
#define dirC_Ka PORTC.2 
#define dirD_Ka PORTC.3 
#include <mega8535.h> 
#include <delay.h> 
bit x; 
unsigned char xcount,lpwm,rpwm; 
// Timer 0 overflow interrupt service routine 
interrupt [TIM0_OVF] void timer0_ovf_isr(void) 
{ 
// Place your code here 
xcount++; 
if(xcount<=lpwm)EnKi=1; 
else EnKi=0; 
if(xcount<=rpwm)EnKa=1; 
else EnKa=0; 
TCNT0=0xFF; // Timer0 Value Menentukan periode pulsa PWM 
} 
void maju() 
{ 
dirA_Ki=1;dirB_Ki=0; 
dirC_Ka=1;dirD_Ka=0; 
} 
void belok_kiri() 
{
unsigned int i; 
lpwm=50; rpwm=50; 
delay_ms(60); // dimajukan sedikit 
dirA_Ki=0;dirB_Ki=1; 
dirC_Ka=1;dirD_Ka=0; 
for(i=0;i<=1000;i++) while (!SkiXX ||!SkiX) {}; 
for(i=0;i<=1000;i++) while ( SkiXX || SkiX) {}; 
lpwm=0; rpwm=0; 
} 
void belok_kanan() 
{ 
unsigned int i; 
lpwm=50; rpwm=50; 
delay_ms(60); // dimajukan sedikit 
dirA_Ki=1;dirB_Ki=0; 
dirC_Ka=0;dirD_Ka=1; 
for(i=0;i<=1000;i++) while (!SkaXX ||!SkaX) {}; 
for(i=0;i<=1000;i++) while ( SkaXX || SkaX) {}; 
lpwm=0; rpwm=0; 
} 
// Declare your global variables here 
unsigned char sensor; 
void scan_rule1() 
{ maju(); 
sensor=PIND; 
sensor&=0b00111111; 
switch(sensor) 
{ case 0b00111110: rpwm=0; lpwm=200; x=1; break;
case 0b00111100: rpwm=50; lpwm=200; x=1; break; 
case 0b00111101: rpwm=75; lpwm=200; x=1; break; 
case 0b00111001: rpwm=100; lpwm=200; x=1; break; 
case 0b00111011: rpwm=150; lpwm=200; x=1; break; 
case 0b00110011: rpwm=200; lpwm=200; break; 
case 0b00110111: rpwm=200; lpwm=150; x=0; break; 
case 0b00100111: rpwm=200; lpwm=100; x=0; break; 
case 0b00101111: rpwm=200; lpwm=75; x=0; break; 
case 0b00001111: rpwm=200; lpwm=50; x=0; break; 
case 0b00011111: rpwm=200; lpwm=0; x=0; break; 
case 0b00111111: break; 
if(x) {lpwm=50; rpwm=0; break;} 
else {lpwm=0; rpwm=50; break;} 
} 
} 
void scan_count(unsigned char count) 
{ 
unsigned int i; 
unsigned char xx=0; 
while(xx<count) 
{ for(i=0;i<1000;i++) while((sensor & 0b00011110)!=0b00000000) scan_rule1(); 
for(i=0;i<1000;i++) while((sensor & 0b00011110)==0b00000000) scan_rule1(); 
xx++; 
} 
} 
void main(void) 
{ 
// Declare your local variables here
// Input/Output Ports initialization 
// Port A initialization 
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In 
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T 
PORTA=0x00; 
DDRA=0x00; 
// Port B initialization 
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In 
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T 
PORTB=0x00; 
DDRB=0x00; 
// Port C initialization 
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out 
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0 
PORTC=0x00; 
DDRC=0xFF; 
// Port D initialization 
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In 
// State0=P State1=P State2=P State3=P State4=P State5=P State6=P State7=P 
PORTD=0xFF; 
DDRD=0x00; 
// Timer/Counter 0 initialization 
// Clock source: System Clock 
// Clock value: 10,800 kHz 
// Mode: Normal top=FFh 
// OC0 output: Disconnected 
TCCR0=0x05; 
TCNT0=0x00;
OCR0=0x00; 
// Timer/Counter 1 initialization 
// Clock source: System Clock 
// Clock value: Timer 1 Stopped 
// Mode: Normal top=FFFFh 
// OC1A output: Discon. 
// OC1B output: Discon. 
// Noise Canceler: Off 
// Input Capture on Falling Edge 
TCCR1A=0x00; 
TCCR1B=0x00; 
TCNT1H=0x00; 
TCNT1L=0x00; 
OCR1AH=0x00; 
OCR1AL=0x00; 
OCR1BH=0x00; 
OCR1BL=0x00; 
// Timer/Counter 2 initialization 
// Clock source: System Clock 
// Clock value: Timer 2 Stopped 
// Mode: Normal top=FFh 
// 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=0x01; 
// Analog Comparator initialization 
// Analog Comparator: Off 
// Analog Comparator Input Capture by Timer/Counter 1: Off 
// Analog Comparator Output: Off 
ACSR=0x80; 
SFIOR=0x00; 
// Global enable interrupts 
#asm("sei") 
while (1) 
{ 
// Place your code here 
scan_count(3); 
belok_kanan(); 
}; 
}

Mais conteúdo relacionado

Mais procurados

Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUs
Corrado Santoro
 
Guia de configuracao_ms9520
Guia de configuracao_ms9520Guia de configuracao_ms9520
Guia de configuracao_ms9520
plisleo
 

Mais procurados (20)

Uart
UartUart
Uart
 
Solution on Portable Blood Pressure Monitor System
Solution on Portable Blood Pressure Monitor SystemSolution on Portable Blood Pressure Monitor System
Solution on Portable Blood Pressure Monitor System
 
DDAA FPGA - Multiplexor De Numeros en Display 7 Segmentos En Tiempo
DDAA   FPGA - Multiplexor De Numeros en Display 7 Segmentos En TiempoDDAA   FPGA - Multiplexor De Numeros en Display 7 Segmentos En Tiempo
DDAA FPGA - Multiplexor De Numeros en Display 7 Segmentos En Tiempo
 
Timer 0 programming on LPC 1768
Timer 0 programming on LPC 1768Timer 0 programming on LPC 1768
Timer 0 programming on LPC 1768
 
FPGA Tutorial - LCD Interface
FPGA Tutorial - LCD InterfaceFPGA Tutorial - LCD Interface
FPGA Tutorial - LCD Interface
 
UART MCU
UART MCUUART MCU
UART MCU
 
Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUs
 
Dm74 ls164
Dm74 ls164Dm74 ls164
Dm74 ls164
 
Apple 1 manual & warranty 1976
Apple 1 manual & warranty 1976Apple 1 manual & warranty 1976
Apple 1 manual & warranty 1976
 
FAR/MARS Avionics CDR
FAR/MARS Avionics CDRFAR/MARS Avionics CDR
FAR/MARS Avionics CDR
 
Handling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUsHandling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUs
 
Sua chua may lanh cua daikin
Sua chua may lanh cua daikinSua chua may lanh cua daikin
Sua chua may lanh cua daikin
 
The Emerald Datasheet
The Emerald DatasheetThe Emerald Datasheet
The Emerald Datasheet
 
Guia de configuracao_ms9520
Guia de configuracao_ms9520Guia de configuracao_ms9520
Guia de configuracao_ms9520
 
Exception handling on the x86
Exception handling on the x86Exception handling on the x86
Exception handling on the x86
 
Exception handling on the x86
Exception handling on the x86Exception handling on the x86
Exception handling on the x86
 
Things you should know for network programming
Things you should know for network programmingThings you should know for network programming
Things you should know for network programming
 
Mitsubachi Arduino code
Mitsubachi Arduino codeMitsubachi Arduino code
Mitsubachi Arduino code
 
Keyless Door Entry via Bluetooth Technology
Keyless Door Entry via Bluetooth TechnologyKeyless Door Entry via Bluetooth Technology
Keyless Door Entry via Bluetooth Technology
 
Affinity quick start guide issue 3
Affinity quick start guide issue 3Affinity quick start guide issue 3
Affinity quick start guide issue 3
 

Destaque (6)

A3 planta baixa térreo
A3   planta baixa térreoA3   planta baixa térreo
A3 planta baixa térreo
 
Residencial Salinas
Residencial SalinasResidencial Salinas
Residencial Salinas
 
Projeto eletrico pdf
Projeto eletrico pdfProjeto eletrico pdf
Projeto eletrico pdf
 
Hydros V4 - Incêndio
Hydros V4 - Incêndio Hydros V4 - Incêndio
Hydros V4 - Incêndio
 
Planta baixa para projeto elétrico iluminação a4 layout1
Planta baixa para projeto elétrico iluminação a4 layout1Planta baixa para projeto elétrico iluminação a4 layout1
Planta baixa para projeto elétrico iluminação a4 layout1
 
Apostila CEFET - Instalações Elétricas
Apostila CEFET - Instalações ElétricasApostila CEFET - Instalações Elétricas
Apostila CEFET - Instalações Elétricas
 

Semelhante a Lampiran 1.programdocx

What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
SIGMATAX1
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
forwardcom41
 
Data Acquisition
Data AcquisitionData Acquisition
Data Acquisition
azhar557
 
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
mayank272369
 
Vhdl practical exam guide
Vhdl practical exam guideVhdl practical exam guide
Vhdl practical exam guide
Eslam Mohammed
 

Semelhante a Lampiran 1.programdocx (20)

What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
eece237lab2EECE237Lab2.uvproj 1.1 ### uVision .docx
eece237lab2EECE237Lab2.uvproj    1.1   ### uVision .docxeece237lab2EECE237Lab2.uvproj    1.1   ### uVision .docx
eece237lab2EECE237Lab2.uvproj 1.1 ### uVision .docx
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 
W8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational ProcessorW8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational Processor
 
Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prog
 
FINISHED_CODE
FINISHED_CODEFINISHED_CODE
FINISHED_CODE
 
Data Acquisition
Data AcquisitionData Acquisition
Data Acquisition
 
0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1
 
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
Fpga creating counter with internal clock
Fpga   creating counter with internal clockFpga   creating counter with internal clock
Fpga creating counter with internal clock
 
selected input/output - sensors and actuators
selected input/output - sensors and actuatorsselected input/output - sensors and actuators
selected input/output - sensors and actuators
 
Product catlog
Product catlogProduct catlog
Product catlog
 
CC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver ModuleCC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver Module
 
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam Guide
 
Vhdl practical exam guide
Vhdl practical exam guideVhdl practical exam guide
Vhdl practical exam guide
 
Em s7 plc
Em s7 plcEm s7 plc
Em s7 plc
 

Mais de Lugik kristiyanto (6)

Lampiran 3 datasheet
Lampiran 3 datasheet Lampiran 3 datasheet
Lampiran 3 datasheet
 
Lampiran 2 rangkaian
Lampiran 2 rangkaianLampiran 2 rangkaian
Lampiran 2 rangkaian
 
Kata pengantar
Kata pengantarKata pengantar
Kata pengantar
 
Daftar isi
Daftar isiDaftar isi
Daftar isi
 
Cover
CoverCover
Cover
 
Komponen elektromekanik
Komponen elektromekanikKomponen elektromekanik
Komponen elektromekanik
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 

Lampiran 1.programdocx

  • 1. LAMPIRAN 1.PROGRAM ROBOT /********************************************* This program was produced by the CodeWizardAVR V1.24.0 Standard Automatic Program Generator © Copyright 1998-2003 HP InfoTech s.r.l. http://www.hpinfotech.ro e-mail:office@hpinfotech.ro Project : Version : Date : 17/11/2013 Author : hendawan Company : Comments: Chip type : Atmega32 Program type : Application Clock frequency : 12,000000 MHz Memory model : Small External SRAM size : 0 Data Stack size : 128 *********************************************/ #define SkiXX PIND.0 #define SkiX PIND.1 #define Ski PIND.2 #define Ska PIND.3 #define SkaX PIND.4 #define SkaXX PIND.5
  • 2. #define EnKi PORTC.4 #define dirA_Ki PORTC.0 #define dirB_Ki PORTC.1 #define EnKa PORTC.5 #define dirC_Ka PORTC.2 #define dirD_Ka PORTC.3 #include <mega8535.h> #include <delay.h> bit x; unsigned char xcount,lpwm,rpwm; // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isr(void) { // Place your code here xcount++; if(xcount<=lpwm)EnKi=1; else EnKi=0; if(xcount<=rpwm)EnKa=1; else EnKa=0; TCNT0=0xFF; // Timer0 Value Menentukan periode pulsa PWM } void maju() { dirA_Ki=1;dirB_Ki=0; dirC_Ka=1;dirD_Ka=0; } void belok_kiri() {
  • 3. unsigned int i; lpwm=50; rpwm=50; delay_ms(60); // dimajukan sedikit dirA_Ki=0;dirB_Ki=1; dirC_Ka=1;dirD_Ka=0; for(i=0;i<=1000;i++) while (!SkiXX ||!SkiX) {}; for(i=0;i<=1000;i++) while ( SkiXX || SkiX) {}; lpwm=0; rpwm=0; } void belok_kanan() { unsigned int i; lpwm=50; rpwm=50; delay_ms(60); // dimajukan sedikit dirA_Ki=1;dirB_Ki=0; dirC_Ka=0;dirD_Ka=1; for(i=0;i<=1000;i++) while (!SkaXX ||!SkaX) {}; for(i=0;i<=1000;i++) while ( SkaXX || SkaX) {}; lpwm=0; rpwm=0; } // Declare your global variables here unsigned char sensor; void scan_rule1() { maju(); sensor=PIND; sensor&=0b00111111; switch(sensor) { case 0b00111110: rpwm=0; lpwm=200; x=1; break;
  • 4. case 0b00111100: rpwm=50; lpwm=200; x=1; break; case 0b00111101: rpwm=75; lpwm=200; x=1; break; case 0b00111001: rpwm=100; lpwm=200; x=1; break; case 0b00111011: rpwm=150; lpwm=200; x=1; break; case 0b00110011: rpwm=200; lpwm=200; break; case 0b00110111: rpwm=200; lpwm=150; x=0; break; case 0b00100111: rpwm=200; lpwm=100; x=0; break; case 0b00101111: rpwm=200; lpwm=75; x=0; break; case 0b00001111: rpwm=200; lpwm=50; x=0; break; case 0b00011111: rpwm=200; lpwm=0; x=0; break; case 0b00111111: break; if(x) {lpwm=50; rpwm=0; break;} else {lpwm=0; rpwm=50; break;} } } void scan_count(unsigned char count) { unsigned int i; unsigned char xx=0; while(xx<count) { for(i=0;i<1000;i++) while((sensor & 0b00011110)!=0b00000000) scan_rule1(); for(i=0;i<1000;i++) while((sensor & 0b00011110)==0b00000000) scan_rule1(); xx++; } } void main(void) { // Declare your local variables here
  • 5. // Input/Output Ports initialization // Port A initialization // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTA=0x00; DDRA=0x00; // Port B initialization // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTB=0x00; DDRB=0x00; // Port C initialization // Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out // State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0 PORTC=0x00; DDRC=0xFF; // Port D initialization // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=P State1=P State2=P State3=P State4=P State5=P State6=P State7=P PORTD=0xFF; DDRD=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 10,800 kHz // Mode: Normal top=FFh // OC0 output: Disconnected TCCR0=0x05; TCNT0=0x00;
  • 6. OCR0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer 1 Stopped // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2 output: Disconnected ASSR=0x00; TCCR2=0x00; TCNT2=0x00; OCR2=0x00; // External Interrupt(s) initialization // INT0: Off
  • 7. // INT1: Off // INT2: Off MCUCR=0x00; MCUCSR=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x01; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off // Analog Comparator Output: Off ACSR=0x80; SFIOR=0x00; // Global enable interrupts #asm("sei") while (1) { // Place your code here scan_count(3); belok_kanan(); }; }