// RGB kytka //Import libraries #include #include // PIC12F1571 configurations // CONFIG1 #pragma config FOSC = INTOSC // (INTOSC oscillator; I/O function on CLKIN pin) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config PLLEN = OFF // PLL Enable (4x PLL disabled) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LPBOREN = OFF // Low Power Brown-out Reset enable bit (LPBOR is disabled) #pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) #define _XTAL_FREQ 16000000 void Wait(unsigned int ms) // časovací funkce po 1 milisekundě { for(int bb = 0; bb < ms; bb++) __delay_ms(1); } void main () { TRISA = 0; ANSELA = 0; LATA = 0; // nastavení digitáních výstupů na všech pinech OSCCON = 0b01111010; // nastavení interního oscillatoru na 16 MHz // nastavení PWM na 3 kanálech (frekvence spínání 200 Hz) PWM1CON = 0b11000000; PWM2CON = 0b11000000; PWM3CON = 0b11000000; PWM1CLKCON = 0; PWM2CLKCON = 0; PWM3CLKCON = 0; PWM1PR = 65535; PWM2PR = 65535; PWM3PR = 65535; PWM1PH = 0; PWM2PH = 0; PWM3PH = 0; PWM1DC = 0; PWM2DC = 0; PWM3DC = 0; while(1) // nekonečná smyčka { PWM1DC = rand()*2; PWM2DC = rand()*2; PWM3DC = rand()*2; // zápis náhodných hodnot pro PWM jednotlivých barev PWM1LD = 1; PWM2LD = 1; PWM3LD = 1; // spuštění PWM s novými hodnotami Wait(10000); // čekej 10 sekund na změnu barvy } }