thilan d
Newbie level 3
- Joined
- Jan 15, 2014
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 47
Hi friends...
am trying to do some PWM effected LED setup with portc and tmr0.. but i can only light up 3 leds each time
can some one help me to light up other leds that connected to port c please
thx a lot
""
""
am trying to do some PWM effected LED setup with portc and tmr0.. but i can only light up 3 leds each time
can some one help me to light up other leds that connected to port c please
thx a lot
""
Code C - [expand] 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 #include <htc.h> #include <stdlib.h> #include <pic.h> #define _XTAL_FREQ 40000000 #define BLUE RC0 #define RED RC7 #define GREEN RC5 #define BROWN RC3 #define BLACK RC4 #define YELLOW RC2 #define ORANGE RC6 #define ASH RC1 #define ON 1 #define OFF 0 unsigned char pwmCounter = 0; unsigned char redActual, redTarget, greenActual, greenTarget, blueActual, blueTarget; unsigned char brownActual, brownTarget, blackActual, blackTarget, yellowActual, yellowTarget; unsigned char orangeActual, orangeTarget, ashActual, ashTarget; unsigned char fade = 0; void main(void) { TRISC = 0; PORTC = 0; T0CS = 0; // Internal Mode (Fosc/4) PSA = 0; // Prescaler assigned to TMR0 PS2 = 1; PS1 = 0; PS0 = 0; // Prescaler ratio 1:32 T0IE = 1; // TMR0 overflow int. enable GIE = 1; // Global int. enable TMR0 = 131; // (256-125=131) for 4mS time //Set up initial LEDs off redActual = 0; greenActual = 0; blueActual = 0; brownActual = 0; blackActual =0; yellowActual = 0; orangeActual =0; ashActual = 0; redTarget = 0; greenTarget = 0; blueTarget = 0; brownTarget = 0; blackTarget = 0; yellowTarget = 0; orangeTarget = 0; ashTarget = 0; while (1) { redTarget = rand() % 60; greenTarget = rand() % 60; blueTarget = rand() % 60; brownTarget = rand() % 60; blackTarget = rand() % 60; yellowTarget = rand() % 60; orangeTarget = rand() % 60; ashTarget = rand() % 60; //Can't do delay higher than 99ms, so chain multiple together for (int delay=0;delay<100;delay++) { __delay_ms(10); } } } void interrupt timer0(void) { if (T0IF == 1) { fade++; if (fade == 64) { if (redTarget > redActual) redActual++; else if (redTarget < redActual) redActual--; if (greenTarget > greenActual) greenActual++; else if (greenTarget < greenActual) greenActual--; if (blueTarget > blueActual) blueActual++; else if (blueTarget < blueActual) blueActual--; if (brownActual > brownActual) brownActual ++; else if (brownActual < brownActual) brownActual --; if (blackActual > blackActual) blackActual ++; else if (blackActual < blackActual) blackActual --; if (yellowActual > yellowActual) yellowActual ++; else if (yellowActual < yellowActual) yellowActual --; if (orangeActual > orangeActual) orangeActual ++; else if (orangeActual < orangeActual) orangeActual --; if (ashActual > ashActual) ashActual ++; else if (ashActual < ashActual) ashActual --; } if (redActual > pwmCounter) { RED = ON; } else { RED = OFF; } if (greenActual > pwmCounter) { GREEN = ON; } else { GREEN = OFF; } if (blueActual > pwmCounter) { BLUE = ON; } else { BLUE = OFF; } if (brownActual > pwmCounter) { BROWN = ON; } else { BROWN = OFF; } if (blackActual > pwmCounter) { BLACK = ON; } else { BLACK = OFF; } if (yellowActual > pwmCounter) { YELLOW = ON; } else { YELLOW = OFF; } if (orangeActual > pwmCounter) { ORANGE = ON; } else { ORANGE = OFF; } if (ashActual > pwmCounter) { ASH = ON; } else { ASH = OFF; } pwmCounter++; if (pwmCounter > 80) { pwmCounter = 0; } T0IF = 0; } }
Last edited by a moderator: