chrisss
Newbie
Missing CODE/SYNTAX tags ( Added by moderator )
Hello, I’m trying to make a dimmer with the PIC16F877A. I found some code and a circuit that I’m testing to use later.
However, I’m encountering several problems. When I start my simulation, the following message appears:
I’m not sure what the error could be.
Here’s the code I’m using, along with images of my simulation and circuit. code:
However, I’m encountering several problems. When I start my simulation, the following message appears:
[PIC16 MEMORY] PC=0x0A69. Attempt to write unimplemented memory location 0x008F with 0x71 ignored. [U1].
I’m not sure what the error could be.
Here’s the code I’m using, along with images of my simulation and circuit. code:
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 /************************************************************************************** AC Lamp light dimmer with PIC16F877A microcontroller C Code for CCS C compiler Crystal oscillator used @ 20MHz This is a free software with NO WARRANTY. [URL]http://simple-circuit.com/[/URL] ***************************************************************************************/ #define triac_gate PIN_D2 #include <16F877A.h> #device ADC = 10 #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock = 20MHz) #use fast_io(d) #byte OPTION_REG = GETENV("SFR:OPTION_REG") // get OPTION_REG register address #bit INTEDG = OPTION_REG.6 // INTEDG (external interrupt edge) bit address ( OPTION_REG(6) ) int1 ZC = 0; int16 alpha; #INT_EXT // external interrupt ISR void ext_isr(void) { ZC = 1; // toggle external interrupt edge if(INTEDG) INTEDG = 0; else INTEDG = 1; } void main() { output_low(triac_gate); output_drive(triac_gate); setup_adc(ADC_CLOCK_INTERNAL); // set ADC clock source setup_adc_ports(AN0); // configure AN0 pin as analog set_adc_channel(0); // select channel AN0 clear_interrupt(INT_EXT); // clear external interrupt flag bit enable_interrupts(GLOBAL); // enable global interrupts enable_interrupts(INT_EXT); // enable external interrupt delay_ms(500); while(TRUE) { alpha = ( 1023 - read_adc() ) * 10; if (alpha > 9500) alpha = 9500; else if (alpha < 200) alpha = 0; while(ZC == 0) ; // wait for zero crossing event // send firing pulse after alpha delay_us(alpha); output_high(triac_gate); delay_us(200); output_low(triac_gate); ZC = 0; } } // End of code
Last edited by a moderator: