11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PICBASIC</strong> <strong>PLUS</strong> CompilerThe following example illustrates the use of a TMR0 interrupt as acrude clock: -' LCD clock program using ON_INTERRUPT' Uses TMR0 and prescaler.' Nap and Sleep should not be used.' Buttons may be used to set Hours and MinutesREMARKS onDEVICE 16F628ON_INTERRUPT GOTO ClockintDIM Hour as BYTE ' Hour variableDIM Dhour as BYTE ' Display Hour variableDIM Minute as BYTE ' Minute variableDIM Second as BYTE ' Second variableDIM Ticks as BYTE ' Pieces of Seconds variableDim Update as BYTE ' Variable to indicate Update of LCDCMCON = 7' PORTA to digital (for 16F62X devices)CLS' Clear the LCDHour=0:Minute=0:Second=0:Ticks=0 ' Set initial time to 00:00:00Update = 1' Force first display' Set TMR0 to interrupt every 16.384 milliseconds (ms)OPTION_REG = %01010101 ' Set TMR0 configurationINTCON = %10100000 ' Enable TMR0 interrupts' ** Main program loop Updates the LCD with the time **Main: PORTA = 0 ' PORTA lines low to read buttonsTRISA = %00001111' Enable all button pins as inputs' Check any button pressed to set timeIF PORTA.3 = 0 THEN Dec_MinIF PORTA.2 = 0 THEN Inc_Min ' Last 2 buttons set MinuteIF PORTA.1 = 0 THEN Dec_HourIF PORTA.0 = 0 THEN Inc_Hour ' First 2 buttons set HourC_Upd: IF Update = 1 THEN' Check for time to Update screen' Display time as hh:mm:ssDhour = Hour ' Change Hour 0 to 12IF (Hour // 12) = 0 THEN Dhour = Dhour + 1283Copyright Crownhill 2001

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

Saved successfully!

Ooh no, something went wrong!