Example #1
0
int main(void)
{
	cli();
	
	system_clocks_init();
	event_system_init();
	tcc0_init();
	spic_init();
	twi_init();
	platform_init();

	sei();
	
    while (1) 
    {
		//platform_reset();
		//platform_monitor();
		platform_prepareData_Debug();
		delayus(1); // enjoy a microsecond of serene peace
	}
}
Example #2
0
int main()
{
	system_clocks_init();
	
	
	DevComSlave_t* dc = dcs_create(SLAVE_ADDRESS);		
	
	// R/W Line of RS485 buscoupler
	dc->RWPort = ((uint8_t*)(&(PORTD.OUT)));
	dc->RW_bp = PIN5_bp;
	
	dcs_start(UARTD1, dc, F_CPU, 500000);	// Start @ UART0 with 500kbits	
				
	while(1)
	{
		if(dc->NewReceived & DCS_REC_DATA_gm)
		{
			// Do something, access Data ranging from dc.Data[0] .. dc.Data[dc.DataUpperBound]			
			dc->NewReceived &= ~(DCS_REC_DATA_gm); // Reset Flags
		}
	}	
}
Example #3
0
void main(void)
{
unsigned char n;
#pragma optsize- 
#asm("cli")
n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm))) |
	PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
CCP=CCP_IOREG_gc;
PMIC.CTRL=n;
PMIC.INTPRI=0x00;
#pragma optsize_default
system_clocks_init();

ports_init();
usartc0_init();
usartd1_init();
rtc32_init_my();
delay_ms(50);
tcd0_init();
twie_init();
sprintf(info,"start i2c");
monitor();
delay_ms(50);
#asm("sei")
delay_ms(1);
PORTE.OUT=PORTE.OUT|0b00010000;
init_buferU1();
delay_ms(50);
PORTE.OUT=PORTE.OUT&0b11101111;
delay_ms(50);
PORTE.OUT=PORTE.OUT|0b00010000;
init_buferU2();
delay_ms(50);
PORTE.OUT=PORTE.OUT&0b11101111;
delay_ms(50);
PORTE.OUT=PORTE.OUT|0b00010000;
init_buferU3();
delay_ms(50);
PORTE.OUT=PORTE.OUT&0b11101111;
delay_ms(50);
sprintf(info,"buf i2c start ok");
monitor();
delay_ms(50);
PORTE.OUT=PORTE.OUT|0b00010000;
bmp_reg_init();
delay_ms(50);
sprintf(info,"bmp i2c start ok");
PORTE.OUT=PORTE.OUT&0b11101111;
delay_ms(50);
monitor();
delay_ms(100);
spic_init();
sprintf(info,"SPI START");
monitor();
#asm("sei")
delay_ms(200);

check_sd_card();


spic_init();
PORTA.DIRSET=0b00000001;
PORTA.OUTSET = 0b00000001;
delay_ms(10);
PORTA.OUTCLR = 0b00000001;
delay_ms(100);
PORTA.OUTSET = 0b00000001;
delay_ms(10);
ad7705_init(can1cl,mclk4,can1set,set1);
delay_ms(10);
PORTE.OUT=PORTE.OUT&0b11101111;
delay_ms(10);
PORTE.OUT=PORTE.OUT|0b00010000;
sprintf(info,"ad7705 start ok");
monitor();

RESULT=ad7705(1);
S0[7]=RESULT;// Сигнал  усилителя младший
S0[8]=(RESULT>>8); //Сигнал  усилителя старший

// ADCA initialization
adca_init();
// ADCB initialization
adcb_init();

// Timer/Counter 
tcc0_init();
tcc1_init();
tcf0_init();
delay_ms(10);

sprintf(info,"start device");
monitor();
delay_ms(50);

if(Xsave==0xFFFFFFFF)Xsave=0; 
sprintf(info,"START WHILE");
monitor();
delay_ms(50);

if(RTC32.CNT<1454622753) RTC32.CNT=1454622753;

PORTE.OUT=PORTE.OUT&0b11101111;
//прописываем заводской ответ
//!!!! важно смертельно
initzavod();
reginit();



while (1)
{
PORTR.OUTTGL=0b00000010;
//////////////////////////////////////*************************************
//поиск ошибки буфера
//buferU1_error();
//включаю подсветку
//if(error_buf!=0) PORTE.OUT=PORTE.OUT|0b00010000;
init_buferU1();
/////////////////////////////////////////////////////////////////////////////
read_bmp();
///////////////////////////////////////////////////////////////
if((0.0<Tempf&&Tempf<60.0)&&(300.0<p1&&p1<825.0))
{
Tempf_K=Tempf*10.0+2730.0;
S0[11]=Tempf_K;// температура бмп младший
S0[12]=(Tempf_K>>8); //температура бмп  старший
///////////////////////////////////////////////////////////////
S0[15]=p/10;//ДАВЛЕНИЕ бмп младший
S0[16]=(p/10>>8);//ДАВЛЕНИЕ бмп  старший
}

init_buferU2();

if(SD_IN) 
{
get_CNTRTC(&X);
calcDateTime(X, 0, &date1,&time1);
bufform(); 
GETFILNAME();
} 

init_buferU3();

buferU1_opros();
buferU2_opros();
buferU3_opros();
//обработочка
    //21.1 b2 io7  +
     if((U2in.input&0b10000000)==0b10000000) S0[21]=S0[21]|0b00000010;
else if((U2in.input&0b10000000)==0b00000000) S0[21]=S0[21]&0b11111101;
     //21.2 b1 io4 +
     if((U1in.input&0b00010000)==0b00010000) S0[21]=S0[21]|0b00000100;
else if((U1in.input&0b00010000)==0b00000000) S0[21]=S0[21]&0b11111011;  
     //21.3 b1 io5  +
     if((U1in.input&0b00100000)==0b00100000) S0[21]=S0[21]|0b00001000;
else if((U1in.input&0b00100000)==0b00000000) S0[21]=S0[21]&0b11110111;
     //21.4 b1 io1   ----
     if((U1in.input&0b00000010)==0b00000010) S0[21]=S0[21]|0b00010000;
else if((U1in.input&0b00000010)==0b00000000) S0[21]=S0[21]&0b11101111;
     //21.5 b2 io3
     if((U2in.input&0b00001000)==0b00001000) S0[21]=S0[21]|0b00100000;
else if((U2in.input&0b00001000)==0b00000000) S0[21]=S0[21]&0b11011111;
     //21.6 b2 io4
     if((U2in.input&0b00010000)==0b00010000) S0[21]=S0[21]|0b01000000;
else if((U2in.input&0b00010000)==0b00000000) S0[21]=S0[21]&0b10111111;
     //21.6 b3 io6
     if((U3in.input&0b01000000)==0b01000000) S0[21]=S0[21]|0b10000000;
else if((U3in.input&0b01000000)==0b00000000) S0[21]=S0[21]&0b01111111;

//пождиг    
if( (B5upr&0b00000010)==0b00000010 ) { U3out.output=U3out.output|0b00000010; }
else if( (B5upr&0b00000010)==0b00000000 ) {U3out.output=U3out.output&0b11111101;}
//клапан1    
if( (B5upr&0b00000100)==0b00000100 ) {U3out.output=U3out.output|0b00000100;}
else if( (B5upr&0b00000100)==0b00000000 ) {U3out.output=U3out.output&0b11111011;} 
//контрольная кювета    
if( (B5upr&0b00001000)==0b00001000)        {U1out.output=U1out.output&0b00111111;
                                            U1out.output=U1out.output|0b01000000;}

else if((B5upr&0b00001000)==0b00000000)     {U1out.output=U1out.output&0b00111111;
                                             U1out.output=U1out.output|0b10000000;}


//клапан 2    
if( (B5upr&0b00010000)==0b00010000 ) {U3out.output=U3out.output|0b00001000;}
else if( (B5upr&0b00010000)==0b00000000 ) {U3out.output=U3out.output&0b11110111;}
//клапан 3    
if( (B5upr&0b00100000)==0b00100000 ) {U3out.output=U3out.output|0b00010000;}
else if( (B5upr&0b00100000)==0b00000000 ) {U3out.output=U3out.output&0b11101111;}
//реле 1    инверсно
if( (B5upr&0b01000000)==0b01000000 )       {U1out.output=U1out.output&0b11111110;}
else if( (B5upr&0b01000000)==0b00000000 ) {U1out.output=U1out.output|0b00000001;}
//реле 2  инверсно  
if( (B5upr&0b10000000)==0b10000000 )      {U2out.output=U2out.output&0b11111110;}
else if( (B5upr&0b10000000)==0b00000000 ) {U2out.output=U2out.output|0b00000001;}

buferU1_set();
buferU2_set();
buferU3_set(); 
  
//////////////////////////////////////*************************************
//установка даты времени
if ((newtime==1)||(newdate==1)) 
                      {
                                    
                      calcSeconds(date1,time1,0,&X);
                      Xsave=X;//последняя установка
                      set_CNTRTC();
                      newdate=0;
                      newtime=0;
                                      
                      }
                      
                  

                                                  

}
Example #4
0
File: 1.c Project: fffaraz/gpst
void main(void)
{
// Declare your local variables here
unsigned char n;

// Interrupt system initialization
// Optimize for speed
#pragma optsize- 
// Make sure the interrupts are disabled
#asm("cli")
// Low level interrupt: Off
// Round-robin scheduling for low level interrupt: Off
// Medium level interrupt: Off
// High level interrupt: On
// The interrupt vectors will be placed at the start of the Application FLASH section
n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm))) |
	PMIC_HILVLEN_bm;
CCP=CCP_IOREG_gc;
PMIC.CTRL=n;
// Set the default priority for round-robin scheduling
PMIC.INTPRI=0x00;
// Restore optimization for size if needed
#pragma optsize_default

// System clocks initialization
system_clocks_init();

// Ports initialization
ports_init();

// Virtual Ports initialization
vports_init();

// USARTE0 initialization
usarte0_init();

// USARTE1 initialization
usarte1_init();

// USARTF0 initialization
usartf0_init();

// Alphanumeric LCD initialization
// Connections specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTD Bit 0
// RD - PORTD Bit 1
// EN - PORTD Bit 2
// D4 - PORTD Bit 4
// D5 - PORTD Bit 5
// D6 - PORTD Bit 6
// D7 - PORTD Bit 7
// Characters/line: 16
lcd_init(16);

// Globally enable interrupts
#asm("sei")


 a1=255;          
 PORTB.OUT = a1   ; 
 lcd_putsf("START");
delay_ms(2000);
lcd_clear();

printf("START\n");


 PORTB.OUT = 0   ;
   
 delay_ms(1000);   
/* 
 PORTF.OUTCLR = 0b00010000; 
  PORTB.OUTCLR = 0b10000000;
  
  delay_ms(100);
  
   PORTF.OUTSET = 0b00010000; 
 PORTB.OUTSET = 0b10000000;
 
   delay_ms(100);
   
   PORTF.OUTCLR = 0b00010000; 
  PORTB.OUTCLR = 0b10000000;
  
   delay_ms(500);
  */
 PORTF.OUTSET = 0b00010000; 
 PORTB.OUTSET = 0b10000000;
 
delay_ms(1000);

  PORTF.OUTCLR = 0b00010000; 
  PORTB.OUTCLR = 0b10000000;

delay_ms(1000);

putchar_usarte1('A');
putchar_usarte1('T');
//putchar_usarte1('I');
putchar_usarte1('\r');

//putchar_usartf0('A');
//putchar_usartf0('T');
//putchar_usartf0('I');
//putchar_usartf0('\r');

while (1)
      {
      // Place your code here    
      PORTB.OUTTGL = 1;
      PORTB.OUTSET = (PORTF.IN & 0b00100000) << 1;
      PORTB.OUTCLR =!(PORTF.IN & 0b00100000) << 1;
      delay_ms(100);
      }
}