Ср фев 21, 2018 07:39:55
[color=#408040]
#include <pic.h>
#if defined (_16F84)
#warning PIC16F84 selected
_CONFIG (0x03FF1);
flelifedefined(_16F627A)
#warning PIC16F627A with internal oscillator selected
_CONFIG(0x03F70);
<<else
#error Unsupported PICmicro MCU selected
#endif
//Global variable and constant
volatile int RTC = 0;
char PWMCycle;
char PWMDuty;
volatile int PWMLoop;
static bit trisLED @ (unsigned) &TRISB*8+1;//Bits control
static bit LED @ (unsigned) &PORTB*8+1;
const int LEDon = 0; // Led on
const int LEDoff = 1;//Led off
// Interrupts
void interrupt tmr0_int(void)
{
if (T0IF) {
RTC++; //increment counter
switch(PWMDuty) {
case 0:
LED = LEDoff;
break;
case 29:
LED = LEDon;
break;
default:
if (PWMCycle <= PWMDuty)
LED = LEDon;
else
LED = LEDoff;
}
if (++PWMCycle == 30) {
PWMCycle = 0;
PWMLoop++;
}
}
T0IF = 0; //reset flag
}
// Main function
void main(void)
{
OPTION_REG = 0x0D1;
TMR0 = 0;
T0IE = 1;
GIE = 1;
while (1==1) {
if (PWMLoop ==2) {
if (PWMDuty ==0)
PWMDuty =29;
else
PWMDuty--;
PWMLoop = 0;
}
}
}
[/color]
Ср фев 21, 2018 08:42:33
Ср фев 21, 2018 08:56:44
Ср фев 21, 2018 09:10:17
Ср фев 21, 2018 10:18:46
Ср фев 21, 2018 10:27:39
Ср фев 21, 2018 11:05:35
Ср фев 21, 2018 11:22:19
Ср фев 21, 2018 11:33:04
Ср фев 21, 2018 11:52:37
Ср фев 21, 2018 11:55:18
Ср фев 21, 2018 12:45:39
#if defined (_16F84)
#warning PIC16F84 selected
_CONFIG (0x03FF1);
flelifedefined(_16F627A)
#warning PIC16F627A with internal oscillator selected
_CONFIG(0x03F70);
<<else
#error Unsupported PICmicro MCU selected
#endif
static bit trisLED @ (unsigned) &TRISB*8+1;//Bits control
static bit LED @ (unsigned) &PORTB*8+1;
const int LEDon = 0; // Led on
const int LEDoff = 1;//Led off
#define LedOn PORTB &= 1;
#define LedOff PORTB |= 1;
LED = LEDoff;
LED = LEDon;
LedOn;
LedOff;
Ср фев 21, 2018 13:41:15
Ср фев 21, 2018 13:46:58
Ср фев 21, 2018 14:03:55
Ср фев 21, 2018 14:15:18
Ср фев 21, 2018 14:34:19
Ср фев 21, 2018 14:46:47