Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 dimmerVal = PORTA * (-1) + 255;
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 unsigned int zc = 0, i = 0; unsigned int dimmerVal = 0, dummy; sbit Gate_Trigger at LATB7_bit; sbit Gate_Trigger_Direction at TRISB7_bit; struct { int B0:1; int B1:1; int B2:1; int B3:1; int B4:1; int B5:1; int B6:1; int B7:1; int B8:1; int B9:1; int B10:1; int B11:1; int B12:1; int B13:1; int B14:1; int B15:1; } myVar; //Timer interrupt is every 32 us void interrupt() { if(RCIF_bit) { //dimmerVal = UART1_Read() * (-1) + 255; RCIF_bit = 0; } if(INTF_bit) { //INTx interrupt is every 10 ms INTF_bit = 0; //This block executes within 10 us INTE_bit = 0; Gate_Trigger = 0; i = 0; if(dimmerVal == 0) { Gate_Trigger = 1; Delay_us(50); Gate_Trigger = 0; INTE_bit = 1; T0IE_bit = 0; } else {T0IE_bit = 1; TMR0 = 96;} zc = 1; INTEDG_bit = ~INTEDG_bit; } if(TMR0IF_bit) { //This block executes within 10 us TMR0IF_bit = 0; TMR0 = 96; if((zc) && (i == dimmerVal)) { T0IE_bit = 0; INTE_bit = 1; Gate_Trigger = 1; Delay_us(50); Gate_Trigger = 0; zc = 0; } ++i; } } void main() { OPTION_REG = 0x88; ANSELA = 0x00; ANSELB = 0x00; ANSELC = 0x00; ADCON1 = 0x90; IOCBP = 0x00; IOCBN = 0x00; TRISA = 0xFF; TRISB = 0x01; TRISC = 0x80; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; LATA = 0x00; LATB = 0x00; LATC = 0x00; UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; INTEDG_bit = 0; INTF_bit = 0; INTE_bit = 1; PEIE_bit = 1; GIE_bit = 1; while (1) { dummy = PORTA; //dimmerVal = PORTA * (-1) + 255; //asm clrw //asm movf _dummy+0, W asm xorlw 0xFF asm movwf _dimmerVal+0 } }
Every GPIO pin on the PIC12F629/675 except GP3, has a weak pull-up option. .
Code C - [expand] 1 dimmerVal = dimmerVal * (-1) + 255;
Code C - [expand] 1 dimmerVal = dimmerVal ^ 0xFF;
Code C - [expand] 1 dimmerVal ^= 0xFF;