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.
/*
* File: main.c
* Author: Group No 7 (SRMGPC)
* Created on 21 May, 2020, 1:39 PM
*/
#define _XTAL_FREQ 10000000
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF
#include <xc.h>
int level = 0;
int main() {
TRISB = 0x00; // set PORT B for output
PORTB = 0b01001000; // pin 7 and pin 4 of PORT B is high
OPTION_REG = 0b00000111; // set the prescalar to 256
TMR0 = 244; // register value calculated for 0.01 ms delay
TMR0IE = 1;
GIE = 1; //enable global interrupt
PEIE = 1;
while(1) {
if(level == 6) {
RB3 = !RB3; //switching T1
RB6 = !RB6; //switching T4
RB4 = !RB4; //switching T2
RB5 = !RB5; //switching T3
}
RB0 = !RB0; //switching S1
if(level % 2 != 0) {
RB1 = !RB1; //switching S2
}
if(level % 4 == 0) {
RB2 = !RB2; //switching S3
}
level++;
if(level > 15) {
level = 0;
}
}
return 0;
}
void __interrupt() timer_isr(void) {
if(TMR0IF == 1) { // set timer value on overflow
TMR0 = 244; //timer value decrease to 0
TMR0IF = 0; //reset the timer interrupt
}
}
Sorry for that. I have added the circuit.Instead of letting us guess about the implemented multilevel scheme, you may want to post a circuit that shows the switch function.