- /******************************************************************************
- | RGB Light |
- | |
- | Made by: "B.T. Postma" |
- | Description: "een Rood/Groen/Blauw licht, welke continue van kleur |
- | veranderd. Met instellingen voor het aanpassen van |
- | de kleuren, en gemakkelijk veranderen van het door |
- ******************************************************************************/
- #define RED (2) // Poort B1
- #define GREEN (1) // Poort B0
- #define BLUE (16) // Poort B4
- #define CONFIG_RED 100 // Kleur-correctie rood
- #define CONFIG_GREEN 100 // Kleur-correctie groen
- #define CONFIG_BLUE 100 // Kleur-correctie blauw
- #define OUTPUT 0x00 // TRIS(A/B) registers, output
- #define INPUT 0xFF // TRIS(A/B) registers, input
- #define CONFIG_OPTIONREG 0b11011000 /* 7 : Port-B Pull-up disabled
- 6 : Interrupt rising edge RB0/INT
- (Interrupt is not enabled!)
- 5 : TMR0 source internal clock
- 4 : TMR0 increment on high-to-low
- transition RA4. (Not used,
- TMR0 source is not pin RA4)
- 3 : Prescaler assigned to WDT
- 2-0: WDT-rate = 1:1
- */
- #define CONFIG_INTCONREG 0b10100000 /* 7 : Global interrupt enabled
- 5 : TMR0 interrupt enabled
- others: Interrupt disabled
- */
- volatile signed char red = 0; // Weergegeven kleur rood
- volatile signed char blue = 0; // Weergegeven kleur blauw
- volatile signed char green = 0; // Weergegeven kleur groen
- volatile signed char counter = 0; // Teller voor de duty-cycle kleuren
- void changecolour(signed char, signed char, signed char, unsigned long int);
- /*
- Hoofdprogramma
- /*
- void main(void)
- {
- OPTION_REG = CONFIG_OPTIONREG; // Zet TMR0 functies
- INTCON = CONFIG_INTCONREG; // Enable TRM0 interrupt
- TRISB = OUTPUT; // Zet PORTB op output
- PORTB = 0; // Maak PORTB leeg
- while(1)
- {
- changecolour(100,0,0,1000); // Verander naar de kleur rood
- changecolour(0,100,0,1000); // Verander naar de kleur groen
- changecolour(0,0,100,1000); // Verander naar de kleur blauw
- }
- }
- signed char calccolour(signed char counter, signed char newcolour, signed char oldcolour)
- {
- return counter - ((counter - 1) / (newcolour - oldcolour));
- }
- void changecolour(signed char newred, signed char newgreen, signed char newblue, unsigned long int tottime)
- {
- signed char j;
- signed long int i;
- signed char tempred, tempgreen, tempblue;
- tempred = calccolour(101, newred, red);
- tempgreen = calccolour(101, newgreen, green);
- tempblue = calccolour(101, newblue, blue);
- for(j=100 ; j > 0 ; j--)
- {
- for(i=0 ; i < (tottime / 100); i++)
- Delay_us(1);
- if((j == tempred) || (j == -tempred))
- {
- if(tempred > 0)
- red++;
- else
- red--;
- tempred = calccolour(j, newred, red);
- }
- if((j == tempgreen) || (j == -tempgreen))
- {
- if(tempgreen > 0)
- green++;
- else
- green--;
- tempgreen = calccolour(j, newgreen, green);
- }
- if((j == tempblue) || (j == -tempblue))
- {
- if(tempblue > 0)
- blue++;
- else
- blue--;
- tempblue = calccolour(j, newblue, blue);
- }
- }
- }
- void interrupt(void)
- {
- unsigned int temp;
- INTCON &= ~0b00000100;
- TMR0 = 0x20;
- if(++counter > 100)
- counter = 1;
- if(red > 100) red = 100;
- if(green > 100) green = 100;
- if(blue > 100) blue = 100;
- temp = (red * CONFIG_RED) / 100;
- if(temp >= counter)
- PORTB |= RED;
- else
- PORTB &= ~RED;
- temp = (green * CONFIG_GREEN) / 100;
- if(temp >= counter)
- PORTB |= GREEN;
- else
- PORTB &= ~GREEN;
- temp = (blue * CONFIG_BLUE) / 100;
- if(temp >= counter)
- PORTB |= BLUE;
- else
- PORTB &= ~BLUE;
- }
RGB-light2
By: Short | Date: Jan 30 2009 14:51 | Format: None | Expires: never | Size: 4.89 KB | Hits: 1019
Latest pastes
1 hours ago
11 hours ago
1 days ago
2 days ago
2 days ago