Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.7 kB
7
Indexable
Never
#include <SI_EFM8BB1_Register_Enums.h>


void InitDevice(void){
  //Disable Watchdog Timer with key sequence
  WDTCN = 0xDE; //First key
  WDTCN = 0xAD; //Second key
  //Setup Defaults for P1
  P1MDOUT = P1MDOUT_B0__OPEN_DRAIN | P1MDOUT_B1__OPEN_DRAIN |
    P1MDOUT_B2__OPEN_DRAIN | P1MDOUT_B3__OPEN_DRAIN |
    P1MDOUT_B4__PUSH_PULL | P1MDOUT_B5__OPEN_DRAIN |
    P1MDOUT_B6__OPEN_DRAIN | P1MDOUT_B7__OPEN_DRAIN;
  //Enable Weak Pullups
  XBR2 = XBR2_WEAKPUD__PULL_UPS_ENABLED | XBR2_XBARE__ENABLED;
  //Disable Interrupts
  IE = IE_EA__DISABLED | IE_EX0__DISABLED | IE_EX1__DISABLED |
    IE_ESPI0__DISABLED | IE_ET0__DISABLED | IE_ET1__DISABLED |
    IE_ET2__ENABLED | IE_ES0__DISABLED;
}


sbit SW=P0^0;

void DelayTimer(void){
  TMOD = 0x01; //16 BIT MODE
  TCON &= ~(1 << 4); //TR0 = 0 TIMER IS NOW OFF AS 
  TCON &= ~(1 << 5); //TFO=0, TIMER FLAG OFF, TURNING OFF THE TIMER OVERFLOW
    TH0 = 0xCE; 
    TL0 = 27;
    TCON |= 0x10;
}

void MSDelay(unsigned int sec){
  while (sec > 0){
    DelayTimer();
    while (!(TCON & 0x20)); //TFO WAITING TO BE SET
    sec = sec - 1;
  }
}

void main(){
    SW = 1;
	  InitDevice();
    while(1){
        if(SW == 0)
        {
            P1 = 0x66;
            MSDelay(100);
            P1 = 0xCC;
            MSDelay(100);
            P1 = 0x99;
            MSDelay(100);
            P1 = 0x33;
            MSDelay(100);
        }
        else
        {
            P1 = 0x66;
            MSDelay(100);
            P1 = 0x33;
						MSDelay(100);
            P1 = 0x99;
            MSDelay(100);
            P1 = 0xCC;
            MSDelay(100);
                }
            }
        }