/* * File: main.c * Author: HS * * Created on 2013/07/24, 12:45 */ #include "lonly.h" #define LED_G RC1 #define LED_B RC2 #define LED_R RE0 #define SW PORTEbits.RE1 #define SWON 0x02 #define SWLED RC0 // CONFIG1 #pragma config FOSC = ECH // Oscillator Selection (ECH, External Clock, High Power Mode (4-32 MHz): device clock supplied to CLKIN pin) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled) #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 CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled) #pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) #pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config VCAPEN = OFF // Voltage Regulator Capacitor Enable (All VCAP pin functionality is disabled) #pragma config PLLEN = ON // PLL Enable (4x PLL enabled) #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 LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) //writing to EEPROM execute once every edit //__EEPROM_DATA(0x01,0xFF,0x95,0x13,0x64,0x64,0x64,0x76); //__EEPROM_DATA(0x46,0x46,0x64,0x64,0x66,0x46,0x56,0x46); //__EEPROM_DATA(0x64,0x64,0x66,0x46,0x46,0x56,0x64,0x64); //__EEPROM_DATA(0x66,0x64,0x74,0x46,0x46,0x46,0x76,0x64); //__EEPROM_DATA(0x46,0x66,0x64,0x64,0x46,0x47,0x46,0x64); //__EEPROM_DATA(0x46,0x56,0x66,0x64,0x64,0x46,0x46,0x66); //__EEPROM_DATA(0x47,0x46,0x46,0x66,0x65,0x64,0x46,0x46); //__EEPROM_DATA(0x64,0x46,0x46,0x46,0x66,0x64,0x64,0x46); //__EEPROM_DATA(0x64,0x64,0x46,0x56,0x46,0x66,0x64,0x74); //__EEPROM_DATA(0x66,0x64,0x64,0x46,0x46,0x46,0x67,0x64); //__EEPROM_DATA(0x46,0x66,0x74,0x64,0x46,0x46,0x46,0x64); //__EEPROM_DATA(0x46,0x47,0x66,0x64,0x64,0x47,0x46,0x66); //__EEPROM_DATA(0x46,0x46,0x46,0x66,0x64,0x64,0x46,0x46); //__EEPROM_DATA(0x65,0x46,0x46,0x46,0x76,0x64,0x64,0x46); //__EEPROM_DATA(0x64,0x64,0x46,0x46,0x46,0x66,0x64,0x65); //__EEPROM_DATA(0x66,0x64,0x64,0x56,0x46,0x46,0x64,0x64); //__EEPROM_DATA(0x46,0x66,0x65,0x64,0x46,0x46,0x67,0x64); //__EEPROM_DATA(0x46,0x46,0x66,0x64,0x64,0x46,0x46,0x66); //__EEPROM_DATA(0x46,0x47,0x46,0x66,0x64,0x74,0x46,0x46); //__EEPROM_DATA(0x64,0x46,0x46,0x46,0x66,0x64,0x64,0x46); //__EEPROM_DATA(0x74,0x64,0x46,0x46,0x56,0x66,0x64,0x64); //__EEPROM_DATA(0x66,0x64,0x64,0x46,0x46,0x46,0x64,0x65); //__EEPROM_DATA(0x46,0x66,0x64,0x74,0x46,0x46,0x66,0x64); //__EEPROM_DATA(0x46,0x46,0x67,0x64,0x64,0x46,0x47,0x66); //__EEPROM_DATA(0x46,0x46,0x46,0x66,0x64,0x64,0x46,0x46); //__EEPROM_DATA(0x64,0x47,0x46,0x46,0x66,0x74,0x64,0x46); //__EEPROM_DATA(0x64,0x64,0x46,0x46,0x46,0x66,0x64,0x64); //__EEPROM_DATA(0x76,0x64,0x64,0x46,0x56,0x46,0x64,0x64); //__EEPROM_DATA(0x46,0x66,0x64,0x65,0x46,0x46,0x66,0x65); //__EEPROM_DATA(0x46,0x46,0x66,0x64,0x64,0x46,0x46,0x66); //__EEPROM_DATA(0x46,0x46,0x47,0x66,0x64,0x64,0x56,0x46); //__EEPROM_DATA(0x64,0x46,0x46,0x46,0x66,0x64,0x64,0x46); //light chages in linear //unsigned char cmdList[]={ // 0x01,0xFF,0x95,0x13,0x64,0x64,0x64,0x76,0x46,0x46,0x64,0x64,0x66,0x46,0x56,0x46, // 0x64,0x64,0x66,0x46,0x46,0x56,0x64,0x64,0x66,0x64,0x74,0x46,0x46,0x46,0x76,0x64, // 0x46,0x66,0x64,0x64,0x46,0x47,0x46,0x64,0x46,0x56,0x66,0x64,0x64,0x46,0x46,0x66, // 0x47,0x46,0x46,0x66,0x65,0x64,0x46,0x46,0x64,0x46,0x46,0x46,0x66,0x64,0x64,0x46, // 0x64,0x64,0x46,0x56,0x46,0x66,0x64,0x74,0x66,0x64,0x64,0x46,0x46,0x46,0x67,0x64, // 0x46,0x66,0x74,0x64,0x46,0x46,0x46,0x64,0x46,0x47,0x66,0x64,0x64,0x47,0x46,0x66, // 0x46,0x46,0x46,0x66,0x64,0x64,0x46,0x46,0x65,0x46,0x46,0x46,0x76,0x64,0x64,0x46, // 0x64,0x64,0x46,0x46,0x46,0x66,0x64,0x65,0x66,0x64,0x64,0x56,0x46,0x46,0x64,0x64, // 0x46,0x66,0x65,0x64,0x46,0x46,0x67,0x64,0x46,0x46,0x66,0x64,0x64,0x46,0x46,0x66, // 0x46,0x47,0x46,0x66,0x64,0x74,0x46,0x46,0x64,0x46,0x46,0x46,0x66,0x64,0x64,0x46, // 0x74,0x64,0x46,0x46,0x56,0x66,0x64,0x64,0x66,0x64,0x64,0x46,0x46,0x46,0x64,0x65, // 0x46,0x66,0x64,0x74,0x46,0x46,0x66,0x64,0x46,0x46,0x67,0x64,0x64,0x46,0x47,0x66, // 0x46,0x46,0x46,0x66,0x64,0x64,0x46,0x46,0x64,0x47,0x46,0x46,0x66,0x74,0x64,0x46, // 0x64,0x64,0x46,0x46,0x46,0x66,0x64,0x64,0x76,0x64,0x64,0x46,0x56,0x46,0x64,0x64, // 0x46,0x66,0x64,0x65,0x46,0x46,0x66,0x65,0x46,0x46,0x66,0x64,0x64,0x46,0x46,0x66, // 0x46,0x46,0x47,0x66,0x64,0x64,0x56,0x46,0x64,0x46,0x46,0x46,0x66,0x64,0x64,0x46 //}; // // __EEPROM_DATA(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); //linear model //the pace of light changes //write version to EEPROM __EEPROM_DATA(0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00); //4 equally change model unsigned char cmdList[]={ 0x02,0xFF,0x95,0x13, 0x46,0x46,0x46,0x65,0x64,0x46,0x46,0x46,0x65,0x64, 0x42,0x42,0x42,0x68,0x68,0x42,0x42,0x42,0x68,0x68, 0x46,0x46,0x46,0x64,0x74,0x46,0x46,0x46,0x64,0x74, 0x47,0x46,0x46,0x64,0x64,0x47,0x46,0x46,0x64,0x64, 0x42,0x46,0x46,0x64,0x64,0x46,0x46,0x46,0x64,0x64, 0x46,0x87,0x86,0x24,0x24,0x86,0x87,0x86,0x24,0x24, 0x46,0x46,0x46,0x64,0x64,0x46,0x46,0x46,0x64,0x64, 0x46,0x46,0x56,0x64,0x64, 0x01,0x04, 0x46,0x46,0x56,0x64,0x64,0x86,0x86,0x86,0x25,0x24, 0x86,0x86,0x86,0x25,0x24,0x46,0x46,0x46,0x64,0x64, 0x46,0x46,0x46,0x64,0x64,0x46,0x46,0x46,0x64,0x74, 0x46,0x46,0x46,0x64,0x74,0x43,0x42,0x42,0x68,0x68, 0x43,0x42,0x42,0x68,0x68,0x46,0x46,0x46,0x64,0x64, 0x46,0x46,0x46,0x64,0x64,0x46,0x56,0x46,0x64,0x64, 0x46,0x56,0x46,0x64,0x64,0x46,0x46,0x44,0x64,0x64, 0x46,0x46,0x46,0x64,0x64, 0x01,0x02, 0x86,0x86,0x34,0x24,0x24,0x86,0x86,0x14,0x24,0x24, 0x46,0x46,0x64,0x65,0x64,0x46,0x46,0x64,0x65,0x64, 0x46,0x46,0x64,0x64,0x64,0x46,0x46,0x64,0x64,0x64, 0x86,0x86,0x24,0x24,0x34,0x86,0x86,0x24,0x24,0x34, 0x47,0x46,0x64,0x64,0x64,0x47,0x46,0x64,0x64,0x64, 0x46,0x46,0x64,0x64,0x64,0x46,0x46,0x64,0x64,0x64, 0x42,0x52,0x68,0x68,0x68,0x42,0x52,0x68,0x68,0x68, 0x46,0x46,0x65,0x64,0x64, 0x01,0x04, 0x46,0x46,0x65,0x64,0x64,0x46,0x46,0x64,0x64,0x64, 0x46,0x46,0x64,0x64,0x64,0x46,0x46,0x64,0x74,0x64, 0x46,0x46,0x64,0x74,0x64,0x86,0x86,0x24,0x24,0x24, 0x86,0x86,0x24,0x24,0x24,0x46,0x46,0x64,0x64,0x74, 0x46,0x46,0x64,0x64,0x74,0x47,0x46,0x64,0x64,0x64, 0x47,0x46,0x64,0x64,0x64,0x86,0x86,0x24,0x24,0x24, 0x86,0x86,0x24,0x24,0x24,0x46,0x56,0x64,0x64,0x64, 0x46,0x56,0x64,0x64,0x64, }; //-----PIC initialization static void pic_init() { OSCCON = 0x70; // INTERNAL 16MHz x 1 APFCON = 0x00; CM1CON0 = 0x00; CM2CON0 = 0x00; TRISA = 0b00000000; //0x00; RA0-7 for outputs TRISB = 0b11000000; //0xC0; RB6 & RB7 for inputs TRISC = 0b00000000; //0x00; RC0-7 for outputs TRISD = 0b00000000; //0x00; RD0-7 for outputs TRISE = 0b0010; //0x02; RE1 for inputs ANSELA = 0x00; // RA1 for analog inputs ANSELB = 0x00; // RB6 & RB7 for digital inputs ANSELD = 0x00; ANSELE = 0x00; //RE1 for digital inputs PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTE = 0x02; //PORT I/O initialize LATE = 0x00; T2CON = 0; PR2 = 0xFF; TMR2 = 0; CCP1CON = 0x0C; CCP2CON = 0x0C; CCP3CON = 0x0C; CCPTMRS0 = 0; CPSCON0 = 0b00001100; T1CON = 0b11110001; TMR1H = 0; TMR1L = 0; CPSON = 1; TMR2ON = 1; PWM1CON = 0x80; PWM2CON = 0x80; PWM3CON = 0x80; CCP1AS = 1; CCP2AS = 1; CCP3AS = 1; return; } //color codes static void rainbowIlum(){ for(unsigned char br=0;br<128;br++){ CCPR1L = 1; CCPR2L = 1+br; CCPR3L = 255-br; waitms(20); } for(unsigned char br=0;br<128;br++){ CCPR1L = 1; CCPR2L = 128+br; CCPR3L = 128-br; waitms(15); } for(unsigned char br=0;br<128;br++){ CCPR1L = 1+br; CCPR2L = 255-br; CCPR3L = 1; waitms(10); } for(unsigned char br=0;br<128;br++){ CCPR1L = 128+br; CCPR2L = 128-br; CCPR3L = 1; waitms(15); } for(unsigned char br=0;br<128;br++){ CCPR1L = 255-br; CCPR2L = 1; CCPR3L = 1+br; waitms(15); } for(unsigned char br=0;br<128;br++){ CCPR1L = 128-br; CCPR2L = 1; CCPR3L = 128+br; waitms(15); } return; } static void ghostWhite(){ RED = 0xF0; GRE = 0xF0; BLU = 0xFF; return; } static void yellowWhite(){ RED = 0xFF; GRE = 0xFF; BLU = 0x55; return; } static void blue(){ RED = 0x00; GRE = 0x00; BLU = 0xFF; return; } static void green(){ RED = 0x00; GRE = 0xFF; BLU = 0x00; return; } static void red(){ RED = 0xFF; GRE = 0x00; BLU = 0x00; return; } static void purple(){ RED = 0xFF; GRE = 0x00; BLU = 0xFF; return; } static void aqua(){ RED = 0x00; GRE = 0xFF; BLU = 0xFF; return; } static void yellow(){ RED = 0xFF; GRE = 0xFF; BLU = 0x00; return; } static void pink(){ RED = 0xFF; GRE = 0x80; BLU = 0x40; return; } static void lightgreen(){ RED = 0xDD; GRE = 0xFF; BLU = 0x22; return; } static void lightbulb(){ RED = 0xFF; GRE = 0x94; BLU = 0x13; return; } static void sunsetOrange(){ RED = 0xaa; GRE = 0x22; BLU = 0x02; return; } //waitTimer //ms unit void waitms(unsigned char i){ while(i){ __delay_ms(17); i--; } } //sec. unit void waitsec(unsigned char i){ while(i){ waitms(1004); i--; } } //min. unit void waitmin(unsigned char i){ while(i){ waitsec(60); i--; } } void main(void) { unsigned char moden,modeb; char s[8]; int adrmax; pic_init(); //PIC initialization LCD_init(); LCD_clr(); LCD_locate(1,1); LCD_print("Blue Green Red"); moden=SW; modeb=SW; SWLED=1; ADR=0; adrmax=sizeof cmdList; while(1){ rgb_disp(BLU,GRE,RED); waitsec(3); while(1){ pink(); moden=SW; if(moden!=modeb){ waitms(1); if(moden==SW){ modeb=moden; break; } } } SWLED=0; initcode(); while(ADR