#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
//pwm sinyali için fonksiyonların oluşturulması
int pwm = 0;
void InitPWM()
{
TCCR0 |= 1 << WGM00 | 1 << WGM01 | 1 << CS00 | 1 << COM01;
DDRB|= 1 << PIND7;
}
void SetPMOutput(int duty)
{
OCR0 = duty;
}
void Wait()
{
_delay_loop_2(27000);
}
void PWMSTART()
{
for(pwm=0;pwm<255;pwm++)
{
SetPMOutput(pwm);
Wait();
}
}
void PWMSTOP()
{
for (pwm=255;pwm>0;pwm--)
{
SetPMOutput(pwm);
Wait();
}
}
int main(void) {
DDRB |= (1 << PB0);
PORTA = 0xFF;// Port A'yı çıkış olarak ayarlama
DDRB &= ~(0xFE); // Port B'yi giriş olarak ayarla pb0 ariç
// Port B'yi yüksek seviyeye çek
DDRD = 0xFF; // Port D'yi çıkış olarak ayarla
InitPWM();
PORTA |= (1<<PA1);
PORTA |= (1<<PA2);
PORTA |= (1<<PA3);
PORTA |= (1<<PA4);
PORTA |= (1<<PA5);
PORTA |= (1<<PA6);
PORTA |= (1<<PA7);
PWMSTART();
Wait();
_delay_ms(3000);
PORTA &= ~(1<<PA1);
PORTA &= ~(1<<PA2);
PORTA &= ~(1<<PA3);
PORTA &= ~(1<<PA4);
PORTA &= ~(1<<PA5);
PORTA &= ~(1<<PA6);
PORTA &= ~(1<<PA7);
_delay_ms(3000);
while (1) { // Sürekli döngü
PORTB |= _BV(PB0); // LED yak
_delay_ms(100);
PORTB &= ~_BV(PB0); // LED söndür
_delay_ms(100);
uint8_t pb_data = PINB & 0x78; // PB3, PB4, PB5 ve PB6 girişlerini oku
if ((PINB & (1 << PB1)) == (1 << PB1)){//3.vites
if (pb_data == 0x08) { // 0,0,1,0
PORTA |= (1 << PA5);
_delay_ms(15);
PORTA |= (1 << PA2);
_delay_ms(15);
PWMSTART();
}
else
{
PORTA&= ~(1 <<PA5);
PORTA&= ~(1 <<PA2);
PWMSTOP();
}
if (pb_data == 0x00) { // 0,0,0,0 vites2
PORTA |= (1 << PA4);
_delay_ms(15);
PORTA |= (1 << PA2);
_delay_ms(15);
PWMSTART();
}
else
{
PORTA&= ~(1 <<PA4);
PORTA&= ~(1 <<PA2);
PWMSTOP();
}
if (pb_data == 0x10) { // 1,0,0,0 vites1
PORTA |= (1 << PA3);
_delay_ms(15);
PORTA |= (1 << PA2);
_delay_ms(15);
PWMSTART();
}
else
{
PORTA&= ~(1 <<PA3);
PORTA&= ~(1 <<PA2);
PWMSTOP();
}
if (pb_data == 0x94) { // 1,0,1,1
PORTA |= (1 << PA6);
_delay_ms(15);
PORTA |= (1 << PA2);
_delay_ms(15);
PWMSTART();
}
else
{
PORTA&= ~(1 <<PA6);
PORTA&= ~(1 << PA2);
PWMSTOP();
}
}
else{
}
}
uint8_t pb_data = PINB & 0x78; // PB3, PB4, PB5 ve PB6 girişlerini o
if ((PINB & (1 << PB2)) == (1 << PB2)){//geri vites için
if (pb_data == 0x08)//vites 3
{
PORTA |= (1 << PA5);
_delay_ms(15);
PORTA |= (1 << PA1);
_delay_ms(15);
PWMSTART();
}
else
{
PORTA&= ~(1 <<PA5);
PORTA&= ~(1 <<PA1);
PWMSTOP();
}
if (pb_data == 0x00){//vites 2
PORTA |= (1<<PA4);
_delay_ms(15);
PORTA |= (1<<PA1);
_delay_ms(15);
PWMSTART();
}
else
{
PORTA&= ~(1 <<PA4);
PORTA&= ~(1 <<PA1);
PWMSTOP();
}
if (pb_data == 0x10){//vites 1
PORTA |= (1<<PA3);
_delay_ms(15);
PORTA |= (1<<PA1);
_delay_ms(15);
PWMSTART();
}
else
{
PORTA&= (1<<PA3);
PORTA&= (1<<PA1);
PWMSTOP();
}
if (pb_data == 0x94){//vites 4
PORTA|= (1<<PA6);
_delay_ms(15);
PORTA|= (1<<PA1);
_delay_ms(15);
}
else
{
PORTA&= (1<<PA6);
PORTA&= (1<<PA1);
PWMSTOP();
}
}
return 0;
}//ᴡʀɪᴛᴇᴅ ʙʏ 𝘒𝘶𝘴𝘏
bence olabilir ? bilmiyorum demek zor değil mesaj kasmak için de kimsenin emek verdiği şeye bilgisizce yorum yapman hiç hoş değil zaman kaybettireceksin sadece..bence olabilir bro
o arkadaşo boşver kod hakkında senin fikrin neVisual Studio Code kullanmanı önerebilirim sadece hem hataları tespit etmesi daha kolay hem de eklenti olarak çok zengin bir program
Post automatically merged:
bence olabilir ? bilmiyorum demek zor değil mesaj kasmak için de kimsenin emek verdiği şeye bilgisizce yorum yapman hiç hoş değil zaman kaybettireceksin sadece..
teşekkür ederimeline sağlık.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?