MCU kullanırken bizleri en çok zorlayan şeylerden birisi portların yetmemesi.
Burada yazdığım minik proje ile 5 port ile 20 led yakmayı göstermeye çalışacağım. Biraz daha geliştirilip başka amaçlar ile kullanmak mümkün olabilir.
İyi eğlenceler…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include <stdio.h> #include <stdlib.h> #include <stdint.h> // PIC12F675 Configuration Bit Settings // 'C' source line config statements #include <xc.h> // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. // CONFIG #pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) #pragma config PWRTE = ON // Power-Up Timer Enable bit (PWRT enabled) #pragma config MCLRE = OFF // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD) #pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled) #pragma config CP = ON // Code Protection bit (Program Memory code protection is enabled) #pragma config CPD = ON // Data Code Protection bit (Data memory code protection is enabled) #define _XTAL_FREQ 4000000 const uint8_t p[] = {0x01, 0x02, 0x01, 0x04, 0x01, 0x10, 0x01, 0x20, 0x02, 0x04, 0x02, 0x10, 0x02, 0x20, 0x04, 0x10, 0x04, 0x20, 0x10, 0x20}; const uint8_t t[] = {0x3C, 0x3C, 0x3A, 0x3A, 0x2E, 0x2E, 0x1E, 0x1E, 0x39, 0x39, 0x2D, 0x2D, 0x1D, 0x1D, 0x2B, 0x2B, 0x1B, 0x1B, 0x0F, 0x0F}; /* * */ void mcuInit(void) { ANSEL = 0x00; CMCON = 0x07; OPTION_REG = 0b00000000; VRCON = 0b00000000; WPU = 0b00100000; } /* * */ void main(void) { uint8_t sayi = 0; mcuInit(); while(1) { for(sayi = 0; sayi < 20; sayi++) { TRISIO = t[sayi]; GPIO = p[sayi]; __delay_ms(500); GPIO = 0; } } } |