12.07.2015 Views

PICREF-4 - Laurent Deschamps

PICREF-4 - Laurent Deschamps

PICREF-4 - Laurent Deschamps

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PICREF</strong>-4APPENDIX C:SOFTWARE PROGRAM#pragma option v;#include /********************************************************//* DIMMER.C/*/* Lamp dimmer for the 12C508./* This program uses the internal 4MHz oscillator/* To drive TRIAC, the output is taken high/* or put in high-impeadance(open drain) to release it/*/* NOTE: This program is designed to work with a 60Hz/* line frequency, it must be modified if used/* on a 50Hz AC line./*/* GPIO = Dim button/* GPIO = No Connect/* GPIO = Output to TRIAC/* GPIO = Bright Button/* GPIO = Zero Crossing sense input/* GPIO = No Connect/********************************************************/#defineBrtbut GPIO.0//Brighten button#define Output GPIO.2//Output to TRIAC#define Dimbut GPIO.3//Dim button#define LineInput GPIO.4//AC line zero crossing sensevoid Buttoncheck(void);unsigned int PercentOn, Maxdim;unsigned int TestCheck, Outcount, TestCount;unsigned int DelayCnt;unsigned int LastBoth, FirstPass;unsigned int Count;const Maxbrt = 0xFD, NotInTest = 3;void main(){PercentOn = 0xD0;Maxdim = 0x70;TestCheck = 0;Outcount = 0;TestCount = 0;DelayCnt = NotInTest;LastBoth = 0;FirstPass = 1;Count = 0;for(Count = 0; Count < 60; Count++){while(LineInput == 1);while(LineInput == 0);CLRWDT;}WREG = 0x85;#asm ( OPTION);WREG = 0x1D;#asm ( TRIS GPIO);//Button check routine//Global variables//On Period//Value of Maximum dimming//Test mode check counter//Counter for test mode exit//Test mode counter//Delay count//Both buttons pressed last time flag//Indicate power-up//General counter//Allow power supply to stabilize//1:64 tmr0 prescaler, pullups enabled//Set up I/OGPIO = 0x04;//Set TRIAC output latch highwhile(LineInput == 1)CLRWDT;TMR0 = PercentOn;while(TMR0 >= 3 && LineInput == 0)CLRWDT;while(1)//Synch to line phase//Get Delay time//Delay to enter main at proper point//Stay in this loop© 1997 Microchip Technology Inc. DS40171A-page 11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!