Exemplo n.º 1
0
void main(void)
{	
	WDTCN = 0xde; // 禁止看门狗定时器
    WDTCN = 0xad;
	Init_Device();
	Timer3_Init(SYSCLOCK/12/800);
	EA=1;
	while(1)
	{;}


}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------
void main (void)
{

    Init_Device ();                     // Initializes hardware peripherals

    EA = 1;                             // Enable global interrupts

    LED = 0;

    while (1);                          // Loop forever

}
Exemplo n.º 3
0
void main(void)
{
	PCA0MD &= ~0x40; 
	Init_Device();
			ADC0MD=0x81;
	flag_adc=0;
	while (1)
		if (flag_adc)
		{
		otv();
	flag_adc=0;
		}
}
Exemplo n.º 4
0
bool Renderer_Init( unsigned width, unsigned height, const char* title )
{
	Window_Init( width, height, title, FULL_SCREEN );

	bool Initialisation = false;

	Initialisation = Init_Device();
        
    assert( Initialisation );

	Initialisation = Init_Vertex_Buffer();

	assert( Initialisation );

	Setup_Rasterization();

	return Initialisation;
}
Exemplo n.º 5
0
void main(void)
{
	char uart1_high = 0; //Flag to indicate UART1's priority level (0 = low, 1 = high)
	char i;
	WDTCN = 0xDE;						// Disable the watchdog timer
	WDTCN = 0xAD;

	Init_Device();
	while(1)
	{
		// Alternate UART interrupt prioritys to check both interrupts equally
		for (i = 0; i < 100; i++) {} //do nothing
		if(uart1_high)
			EIP2 &= ~0x40; //Set UART1 priority to low
		else
			EIP2 |= 0x40;//Set UART1 priority to high
	}

}
Exemplo n.º 6
0
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main (void) {

	
	Intensite=80; // en %
	Lum_ON=20;// choisir valeur entre 1 et 100
	Lum_OFF=10;// choisir valeur entre 1 et 100 
	Lum_Nbre=10; 
	cpt=0;
	ON=1;
	nbOverflow=Lum_ON*4; // (x*10^-1)/(25*10^-3) rappel: un overflow tt les 25 ms
	
	Init_Device();
	PCA_Init();
	EA=1; // Autorisation interruptions
	
	Lumiere();
	while (1) { // Boucle infinie
	
	}
}
Exemplo n.º 7
0
void main(void)
{
	u32 cnt = 0;

	Init_Device();	  //use code generate by silicon tool.

	TI0 = 1; 			//make uart0 in send enable status
//-----------------------------------------
	event_init();
//-----------------------------------------add a timer event for printf
#if 0
{
   	timer_ev_unit_st xdata unit;
	timer_event_init();
	unit.event = EVENT_ID_TIMER_DEBUG;
	unit.time = TRIG_TIME;
	unit.callback = func_for_debug;
	timer_event_add(&unit);
}
#endif
//-----------------------------------------




	report_handler_init();

//	while(cnt++<65536);
//	config_sensor();

	test_func();

 	Usb_Init();
	
	Interrupts_Init();	   //open relative interrupt.

   	//g_panel_point.ID = 0;
 	//g_panel_point.x  = 0;
	//g_panel_point.y  = 0;

	while (1)
	{
		event_process();
		
		if(g_work_style == WORK_STYLE_PREVIEW)
		{
			get_frame_data();
			//while(EP_STATUS[1] != 0);
			send_debug_info_to_host(REPORT_ID_IN_DBGINFO);
		}
		else if(g_work_style == WORK_STYLE_CAL)
		{
		 
		}
		else if(g_work_style == WORK_STYLE_NOMAL)
		{ /*
		 	g_panel_point.x +=200;
			g_panel_point.y +=100;

			g_panel_point.x %= 1600;
			g_panel_point.y %= 900;

			fill_hid_packet(&g_panel_point,1); 
			send_debug_info_to_host(REPORT_ID_IN_MTOUCH);	
		   */
		}
		

	}

}
Exemplo n.º 8
0
void main()
{
	unsigned char c;

	Init_Device();

	CheckSRAMs();

	LED=0;
	adc_select=3;
	ADC0ConfigEven=ADC0ConfigOdd=0;		// adc0 gain and channel selection for every even sample and every odd sample
	ADC1ConfigEven=ADC1ConfigOdd=0;
	DAC0_mode=0;
	handshake=1;
	dac_increment=1;
	dac_amplitude=255;
	dac_offset=0;
	fifo_size=128;	// default number of samples in a block

	RTS=0;

	while (1)
	{
		while (SInOut()!='@');
		c=SInOut();
		if (c=='I')
		{
			SendID();
		}
		else if (c=='x')	// switch reference voltage and resistors
		{
			c=SInOut();
			SW0 = !(c&1);	// 1: 10k resistor connected to input, 0: input floating
			SW1 = !(c&2);
			SW2 = !(c&4);
			SW3 = !(c&8);
			PULL = !(c&16);	// 1: pull up to Vref, 0: pull down to GND
		}
		else if (c=='t')	// set trigger polarity
		{
			c=SInOut();
			TRIGINV = c&1;
		}
		else if (c=='b')	// set fifo block size (number of samples in a block
		{
			fifo_size=SInOut();
		}
		else if (c=='c')	// configure continuous sampling mode
		{
			ADC0ConfigEven=SInOut();
			ADC1ConfigEven=SInOut();
			ADC0ConfigOdd=SInOut();
			ADC1ConfigOdd=SInOut();
		}
		else if (c=='S') // start sampling, ESC exits
		{
			ContSampling();
		}
		else if (c=='s') // start sampling, ESC exits
		{
			unsigned long n;

			n = SInOut();
			n = (n << 8)+SInOut();
			n = (n << 8)+SInOut();
			SetSamplingFreq(n);
			n = SInOut();
			n = (n << 8)+SInOut();
			HiSpeedSampling(n);
//			SamplingToSRAM(SInOut());
		}
		else if (c=='A') // select ADCs
		{
			adc_select = SInOut() & 3;
		}
		else if (c=='1') // set range, current, channel
		{
			c=SInOut();
			SetPGA0(c);
		}
		else if (c=='2') // set range, current, channel
		{
			c=SInOut();
			SetPGA1(c);
		}
		else if (c=='M') // measure channels
		{
			c=SInOut();
			if (c<1) c=1;
			Convert(c); // make a single conversion and send data to PC
			SOut(adc1data >> 8);	// channel 0 or 1
			SOut(adc1data);
			SOut(adc0data >> 8);	// channel 2 or 3
			SOut(adc0data);
		}
		else if (c=='f') // set freq
Exemplo n.º 9
0
void main(void)
	{
		PCA0MD &= ~0x40; 
		Init_Device();
		flag_int0 = 0;
		flag_int1 = 0;


		IE0 = 0;
		IE1 = 0;
	//	while (1)
	  {
//	  A01=0;
//	  A01=1; 
		val = read_spi_con(0x01);
//	write_spi_con(0x01,0x21);
	}
	//		write_spi_con(0x10,0x21);
while (1)
{
i =0;
												//	val = read_spi_con(0);
												//	__delay_ms(2);
												//	val = read_spi_con(2);
	  while (i < 0x20)
		  {
				
//for (i = 0 ; i <= 31; i++)
{

} //регистры выставлены
			write_spi_con(i,InitConfigRegs[i]);
												//__delay_ms(2);
												//	 write_spi_con(0x10,i);
													//	 write_spi_con(a,b);

												//	LATAbits.LATA1 = 0;
												//	LATAbits.LATA1 = 1;
				val = read_spi_con(i); 
												//	__delay_ms(2);
				a5 = InitConfigRegs[i];
												//	val = read_spi_con(1); 
				i++;
		}
		i = 0;
		dia();
	   while (i < 0x20)
		  {
				
//for (i = 0 ; i <= 31; i++)
{

} //регистры выставлены
		//	write_spi_con(i,InitConfigRegs[i]);
												//__delay_ms(2);
												//	 write_spi_con(0x10,i);
													//	 write_spi_con(a,b);

												//	LATAbits.LATA1 = 0;
												//	LATAbits.LATA1 = 1;
				val = read_spi_con(i); 
												//	__delay_ms(2);
				a5 = InitConfigRegs[i];
												//	val = read_spi_con(1); 
				i++;
		}
	val = read_spi_con(0x0e);
	write_spi_con(0x0e,(val | 0x02));
	val = read_spi_con(0x0e);
	val = read_spi_con(0x00);
	write_spi_con(0x00,((val & 0x1F) | RF_SYNTHESIZER));
	val = read_spi_con(0x00);
do
{
val = read_spi_con(0x0e);

}
while (!(val & 0x02));
while (1)
Send_Packet_my();
i++;
}


	}
Exemplo n.º 10
0
Arquivo: main.c Projeto: ajmas/NewSRT
int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *button_clear, *button_azel, *button_freq, *button_offset;
    GtkWidget *button_help;
    GdkColor color;
    int i, ii;
    int yr, da, hr, mn, sc;
    double secstart;
    char buf[64];
    GdkGeometry geometry;
    GdkWindowHints geo_mask;
//    GdkRectangle update_rect;
    sprintf(d1.catnam, "srt.cat");
    sprintf(d1.hlpnam, "srt.hlp");
    for (i = 0; i < argc - 1; i++) {
        sscanf(argv[i], "%63s", buf);
        if (strstr(buf, "-c") && strlen(buf) == 2)
            sscanf(argv[i + 1], "%63s", d1.catnam);
        if (strstr(buf, "-h") && strlen(buf) == 2)
            sscanf(argv[i + 1], "%63s", d1.hlpnam);
    }
//    d1.azelport = 0x3f8;        // com1 default for old SRT 
    d1.ver = 4;  // SRT software version
    d1.secs = readclock();
    d1.run = 1;
    d1.record = 0;
    d1.entry1 = d1.entry2 = d1.entry3 = d1.entry5 = d1.entry6 = d1.entry8 = d1.helpwindow = d1.vwindow = 0;
    d1.plot = 0;
    d1.start_time = 0.0;
    d1.start_sec = 0.0;
    d1.speed_up = 0;
    d1.ppos = 0;
    d1.printout = 1;
    d1.debug = 0;
    d1.freq = 1420.4;           // default
    d1.bw = 0;                  // set to 2.4 for TV dongle 10 MHz for ADC card in init
    d1.fbw = 0;                 // set in init or srt.cat
    d1.nblk = 5;                // number of blocks in vspectra
    d1.record_int_sec = 0;
    d1.freqcorr = 0;            // frequency correction for L.O. may be needed for TV dongle
    d1.freqchng = 0;
    d1.clearint = 0;
    d1.record_clearint = 0;
    d1.noclearint = 0;
    d1.nfreq = NSPEC;
    d1.plotsec = 1;
    d1.displ = 1;
    d1.noisecal = 0;
//    used for old SRT mount and controller
//    d1.ptoler = 1;
//    d1.countperstep = 10000;    // default large number for no stepping 
//    d1.elcounts_per_deg = (52.0 * 27.0 / 120.0); // default for H-180
//    d1.azcounts_per_deg = 8.0 * 32.0 * 60.0 / (360.0 * 9.0); // default for CASSIMOUNT
//    d1.rod = 1;                 // default to rod as on CASSIMOUNT
//    d1.rod1 = 14.25;            // rigid arm length
//    d1.rod2 = 16.5;             // distance from pushrod upper joint to el axis
//    d1.rod3 = 2.0;              // pushrod collar offset
//    d1.rod4 = 110.0;            // angle at horizon
//    d1.rod5 = 30.0;             // pushrod counts per inch
    d1.azelsim = d1.radiosim = d1.fftsim = 0;
    d1.mainten = 0;
    d1.stowatlim = 1;
    d1.rms = -1;                // display max not rms 
    d1.calcons = 1.0;
    d1.caldone = 0;
    d1.nrfi = 0;
    d1.rfisigma = 6;            // level for RFI reporting to screen
    d1.tload = 300.0;
    d1.tspill = 20.0;
    d1.beamw = 5.0;
    d1.comerr = 0;
    d1.limiterr = 0;
    d1.restfreq = 1420.406;     /* H-line restfreq */
    d1.delay = 0;
    d1.azoff = 0.0;
    d1.eloff = 0.0;
    d1.drift = 0;
    d1.tstart = 0;
    d1.tsys = 100.0;            // expected on cold sky
    d1.pwroff = 0.0;
    d1.tant = 100.0;
    d1.calpwr = 0;
    d1.yfac = 0;
    d1.calon = 0;
    d1.calmode = 0;
    d1.docal = 0;
    d1.tcal = 290;              // absorber or bushes
    d1.sourn = 0;
    d1.track = 0;
    d1.scan = 0;
    d1.bsw = 0;
    d1.nbsw = 1;
    d1.obsn = 0;
    d1.stopproc = 0;
    d1.fstatus = 0;
    d1.cmdfl = 0;
    d1.south = 1;
    d1.hgt = 0;
    d1.dongle = 0;              // set to zero initially - set to 1 in Init_Device if dongle
    d1.npoly = 25;              // number of terms in polynomial fit of bandpass
    pwrst = pwrprev = 0.0;
    soutrack[0] = 0;
    sprintf(d1.cmdfnam, "cmd.txt");
    sprintf(d1.datadir, "./");  // default to local directory

    if (!catfile())
        return 0;
    d1.foutstatus = 0;
// to get permission su root chown root srtn then chmod u+s srtn then exit 
    if (!d1.azelsim) {
        if (d1.printout)
            printf("initializing antenna controller\n");
        i = rot2(&d1.aznow, &d1.elnow, -1, buf); // initialize
        i = rot2(&d1.aznow, &d1.elnow, 1, buf); // read
        if (i < 0) {
            printf("Couldn't talk to antenna controller\n");
            return 0;
        }
    } else {
        if (d1.stowatlim) {
            d1.azprev = d1.azlim1;
            d1.elprev = d1.ellim1;
        } else {
            d1.azprev = d1.stowaz;
            d1.elprev = d1.stowel;
        }
    }
    setgid(getgid());
    setuid(getuid());
    if (d1.mainten == 0) {
        if (d1.stowatlim) {
            d1.azcmd = d1.azlim1;
            d1.elcmd = d1.ellim1;
        } else {
            d1.azcmd = d1.stowaz;
            d1.elcmd = d1.stowel;
        }
        d1.azcount = 0;
        d1.elcount = 0;
        d1.stow = 1;
    }
    if (d1.azlim1 > d1.azlim2) {
        d1.south = 0;           // dish pointing North for southern hemisphere
        if (d1.azlim2 < 360.0)
            d1.azlim2 += 360.0;
    }

    if (!d1.radiosim)
        Init_Device(0);

    if (d1.displ) {
        gtk_init(&argc, &argv);
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        geometry.min_width = 500;
        geometry.min_height = 300;
        geo_mask = GDK_HINT_MIN_SIZE;
        gtk_window_set_geometry_hints(GTK_WINDOW(window), window, &geometry, geo_mask);
        //Table size determines number of buttons across the top
        table = gtk_table_new(30, NUMBUTTONS, TRUE);

        drawing_area = gtk_drawing_area_new();
        gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
        color.red = 0xffff;
        color.blue = 0xffff;
        color.green = 0xffff;
        gtk_widget_show(drawing_area);
        gtk_table_attach_defaults(GTK_TABLE(table), drawing_area, 0, NUMBUTTONS, 3, 30);

        g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(quit), NULL);

        gtk_container_add(GTK_CONTAINER(window), table);

        g_signal_connect(G_OBJECT(drawing_area), "expose_event", (GtkSignalFunc) expose_event, NULL);
        g_signal_connect(G_OBJECT(drawing_area), "configure_event", (GtkSignalFunc) configure_event, NULL);

        g_signal_connect(G_OBJECT(drawing_area), "button_press_event",
                         (GtkSignalFunc) button_press_event, NULL);

        gtk_widget_set_events(drawing_area, GDK_EXPOSURE_MASK
                              | GDK_LEAVE_NOTIFY_MASK
                              | GDK_BUTTON_PRESS_MASK
                              | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);


        button_clear = gtk_button_new_with_label("clear");
        button_stow = gtk_button_new_with_label("stow");
        button_azel = gtk_button_new_with_label("azel");
        button_npoint = gtk_button_new_with_label("npoint");
        button_bsw = gtk_button_new_with_label("beamsw");
        button_freq = gtk_button_new_with_label("freq");
        button_offset = gtk_button_new_with_label("offset");
        button_record = gtk_button_new_with_label("record");
        button_cmdfl = gtk_button_new_with_label("cmdfl");
        button_cal = gtk_button_new_with_label("cal");
        button_help = gtk_button_new_with_label("help");
        button_exit = gtk_button_new_with_label("exit");

        g_signal_connect(G_OBJECT(button_clear), "clicked", G_CALLBACK(button_clear_clicked), NULL);
        g_signal_connect(G_OBJECT(button_stow), "clicked", G_CALLBACK(button_stow_clicked), NULL);
        g_signal_connect(G_OBJECT(button_azel), "clicked", G_CALLBACK(button_azel_clicked), NULL);
        g_signal_connect(G_OBJECT(button_npoint), "clicked", G_CALLBACK(button_npoint_clicked), NULL);
        g_signal_connect(G_OBJECT(button_bsw), "clicked", G_CALLBACK(button_bsw_clicked), NULL);
        g_signal_connect(G_OBJECT(button_freq), "clicked", G_CALLBACK(button_freq_clicked), NULL);
        g_signal_connect(G_OBJECT(button_offset), "clicked", G_CALLBACK(button_offset_clicked), NULL);
        g_signal_connect(G_OBJECT(button_record), "clicked", G_CALLBACK(button_record_clicked), NULL);
        g_signal_connect(G_OBJECT(button_cmdfl), "clicked", G_CALLBACK(button_cmdfl_clicked), NULL);
        g_signal_connect(G_OBJECT(button_cal), "clicked", G_CALLBACK(button_cal_clicked), NULL);
        g_signal_connect(G_OBJECT(button_help), "clicked", G_CALLBACK(button_help_clicked), NULL);
        g_signal_connect(G_OBJECT(button_exit), "clicked", G_CALLBACK(button_exit_clicked), NULL);

        // test setting up tooltips instead of the "enter"/"leave" used below
        tooltips = gtk_tooltips_new();
        gtk_tooltips_set_tip(tooltips, button_clear,
                             "click to clear integration and reset time plot to 1/4-scale", NULL);
        gtk_tooltips_set_tip(tooltips, button_stow, "click to stow antenna", NULL);
        gtk_tooltips_set_tip(tooltips, button_azel, "click to enter az el coordinates", NULL);
        gtk_tooltips_set_tip(tooltips, button_npoint, "click to start npoint scan", NULL);
        gtk_tooltips_set_tip(tooltips, button_bsw, "click to start beam switch", NULL);
        gtk_tooltips_set_tip(tooltips, button_freq, "click to enter new frequency in MHz [bandwidth] [nfreq]",
                             NULL);
        gtk_tooltips_set_tip(tooltips, button_offset, "click to enter offsets", NULL);
        if (!d1.cmdfl)
            gtk_tooltips_set_tip(tooltips, button_cmdfl, "click to start cmd file", NULL);
        else
            gtk_tooltips_set_tip(tooltips, button_cmdfl, "click to stop cmd file", NULL);

        gtk_tooltips_set_tip(tooltips, button_cal, "click to start calibration", NULL);
        gtk_tooltips_set_tip(tooltips, button_help, "click to open help window", NULL);
        record_tooltip();


        gtk_table_attach(GTK_TABLE(table), button_clear, 0, 1, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_stow, 1, 2, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_azel, 2, 3, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_npoint, 3, 4, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_bsw, 4, 5, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_freq, 5, 6, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_offset, 6, 7, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_record, 7, 8, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_cmdfl, 8, 9, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_cal, 9, 10, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_help, 10, 11, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_exit, 11, 12, 0, 2, GTK_FILL, GTK_FILL, 0, 0);



        gtk_widget_show(button_clear);
        gtk_widget_show(button_stow);
        gtk_widget_show(button_azel);
        gtk_widget_show(button_npoint);
        gtk_widget_show(button_bsw);
        gtk_widget_show(button_freq);
        gtk_widget_show(button_offset);
        gtk_widget_show(button_record);
        gtk_widget_show(button_cmdfl);
        gtk_widget_show(button_cal);
        gtk_widget_show(button_help);
        gtk_widget_show(button_exit);


        gtk_widget_show(table);
        gtk_widget_show(window);
        clearpaint();
    }
    ii = 0;
    if (d1.printout) {
        toyrday(d1.secs, &yr, &da, &hr, &mn, &sc);
        printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource);
    }
    zerospectra(0);
    for (i = 0; i < d1.nfreq; i++)
        bspec[i] = 1;
    secstart = d1.nsecstart = -1;
    d1.secs = readclock();
    while (d1.run) {
        zerospectra(1);
        if (d1.clearint) {
            if (d1.displ)
                cleararea();
            zerospectra(0);
            d1.clearint = 0;
        }
        if (d1.freqchng) {
            if (d1.dongle)
                Init_Device(1);
            if (d1.printout) {
                toyrday(d1.secs, &yr, &da, &hr, &mn, &sc);
                printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource);
            }
            if (!d1.radiosim) {
                sleep(1);
            }
            zerospectra(0);
            d1.freqchng = 0;
        }
        if (d1.docal) {
            if (d1.docal == 1) {
                sprintf(d1.recnote, "* calibration started\n");
                outfile(d1.recnote);
            }
            if (d1.bsw) {
                d1.bsw = 0;
                d1.azoff = 0.0;
            }
            if (d1.scan) {
                d1.scan = 0;
                d1.eloff = d1.azoff = 0.0;
            }
            if (d1.slew)
                d1.slew = 0;
            if (d1.docal == 1)
                cal(0);
            d1.docal = 2;
            cal(1);
            if (d1.integ >= NCAL) {
                cal(2);
                d1.docal = 0;
            }
        }

        if (d1.displ)
            cleararea();
        azel(d1.azcmd, d1.elcmd); // allow time after cal 
        if (d1.comerr == -1)
            return 0;
        if (!d1.slew) {
            pwr = 0.0;
        }
        if (!d1.slew)
            vspectra();
        d1.secs = readclock();
        aver();
        d1.integ2++;
        if (d1.record_int_sec && d1.integ2 >= d1.record_int_sec) {
            outfile(" ");
            if (d1.record_clearint && d1.track && !d1.bsw && !d1.scan)
                d1.clearint = 1;
            d1.integ2 = 0;
        }
        if (d1.displ) {
            if (!d1.plot)
                Repaint();
            while (gtk_events_pending() || d1.stopproc == 1) {
                gtk_main_iteration();
                d1.plot = 0;
            }
        }
        if (!d1.displ && d1.domap)
            scanplot();
    }
    return 0;
}
Exemplo n.º 11
0
//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------
void main (void)
{
 
   unsigned char test_value = 0x55;
   unsigned char test_array[MAX_BUFFER_SIZE] = {1,2,3,4,5,6,7,8};
   unsigned char i;
 
   Init_Device ();                     // Initializes hardware peripherals
 
   EA = 1;                             // Enable global interrupts
  
 
   // TEST BEGIN --------------------------------------------------------------
 
   SPI_Data = test_value;
 
   // Write a value
   SPI_Byte_Write ();
 
   while (!SLVSEL);                    // Wait until the Write transfer has
                                       // finished
 
   // Read the same value back
   SPI_Data = 0x00;
   SPI_Byte_Read ();
 
   while (!SLVSEL);                    // Wait until the Read transfer has
                                       // finished
 
   // Check if the sent value and returned value match
   if (SPI_Data != test_value)
   {
 
      Error_Flag = 1;
    
}
 
   // Copy test_array into SPI_Data_Array
   for (i = 0; i < MAX_BUFFER_SIZE; i++)
   {
 
      SPI_Data_Array[i] = test_array[i];
    
}
 
   // Send the array to the slave
   SPI_Array_Write ();
 
   while (!SLVSEL);                    // Wait until the Write transfer has
                                       // finished
 
   // Clear SPI_Data_Array for the SPI_Buffer_Read function
   for (i = 0; i < MAX_BUFFER_SIZE; i++)
   {
 
      SPI_Data_Array[i] = 0;
    
}
 
   // Read the array back from the slave
   SPI_Array_Read ();
 
   while (!SLVSEL);                    // Wait until the Read transfer has
                                       // finished
 
   // Check if the received array matches the sent array
   for (i = 0; i < MAX_BUFFER_SIZE; i++)
   {
 
      if (SPI_Data_Array[i] != test_array[i])
      {
 
         Error_Flag = 1;
       
}
    
}
 
   // END OF TEST -------------------------------------------------------------
	while(1);
 
}
Exemplo n.º 12
0
void main(void)
{

	WDTCN = 0XDE;		//Kill the Watchdog 
	WDTCN = 0XAD;

	SYSCLK_INIT();		//Initialize the SYSCLK to 22.1184MHz
	Init_Device();

	SFRPAGE = UART0_PAGE;
	printf("\033[2J");	//Clear ANSI terminal

	aa = (short int *)a;//Set *aa & *bb to be the combined hi & low bytes of
	bb = (short int *)b;//a[1], a[0] & b[1], b[0]
	cc = (long int *)c;	//*cc is c[3], c[2], c[1], c[0]
	dd = (short int *)c;//*dd is the low 16 bits of *cc (low short int)

	while (1)
	{

		SFRPAGE = UART0_PAGE;
		printf("\n\rEnter inputs A & B (4 hex digits each):");
// Read in each hex character and echo it back to terminal
// Convert character to numerical value by subtracting offset
// Handle both upper and lower case A-F or a-f accordingly
		d = getchar(); putchar(d); 
		if(d>'`')a3 = d-0x57;
		else if(d>'@')a3 = d-0x37;
		else  a3 = d-0x30;
		d = getchar(); putchar(d); 
		if(d>'`')a2 = d-0x57;
		else if(d>'@')a2 = d-0x37;
		else  a2 = d-0x30;
		d = getchar(); putchar(d);
		if(d>'`')a1 = d-0x57;
		else if(d>'@')a1 = d-0x37;
		else  a1 = d-0x30;
		d = getchar(); putchar(d);
		if(d>'`')a0 = d-0x57;
		else if(d>'@')a0 = d-0x37;
		else  a0 = d-0x30;
		putchar(' '); putchar(' ');

		d = getchar(); putchar(d); 
		if(d>'`')b3 = d-0x57;
		else if(d>'@')b3 = d-0x37;
		else  b3 = d-0x30;
		d = getchar(); putchar(d); 
		if(d>'`')b2 = d-0x57;
		else if(d>'@')b2 = d-0x37;
		else  b2 = d-0x30;
		d = getchar(); putchar(d);
		if(d>'`')b1 = d-0x57;
		else if(d>'@')b1 = d-0x37;
		else  b1 = d-0x30;
		d = getchar(); putchar(d);
		if(d>'`')b0 = d-0x57;
		else if(d>'@')b0 = d-0x37;
		else  b0 = d-0x30;

// Print out hex digits as a check on correctness
		printf("\r\nA: (HEX DIGITS) %01X, %01X, %01X, %01X", a3, a2, a1, a0);
		printf("\r\nB: (HEX DIGITS) %01X, %01X, %01X, %01X", b3, b2, b1, b0);
//		*aa = a0+a1*16+a2*256+a3*4096;	//Combine 4 hex digits into *aa
//		*bb = b0+b1*16+b2*256+b3*4096;	//Combine 4 hex digits into *bb
// A more efficient way is to use shifts instead of multiplies:
		*aa = a0+(a1<<4)+((short int)a2<<8)+((short int)a3<<12);
		*bb = b0+(b1<<4)+((short int)b2<<8)+((short int)b3<<12);
// Now a[1] is the hi byte of *aa and a[0] is the lo byte
// and b[1] is the hi byte of *bb and b[0] is the lo byte

		SFRPAGE = MAC0_PAGE;
		MAC0CF = 0x09;	//Clear MAC and set to multiply only

		MAC0AH = a[1];	//Load the hi byte of *aa
		MAC0AL = a[0];	//Load the lo byte of *aa
		MAC0BH = b[1];	//Load the hi byte of *bb
		MAC0BL = b[0];	//Load the lo byte of *bb & start multiplier

// Need a very short delay before getting result
		SFRPAGE = MAC0_PAGE;//Any dummy statement will work
		c[0] = MAC0ACC0;	//Get the lo 0th byte of product
		c[1] = MAC0ACC1;	//Get the mid 1st byte of product
		c[2] = MAC0ACC2;	//Get the mid 2nd byte of product
		c[3] = MAC0ACC3;	//Get the hi 3rd byte of product
		ans = *cc;			//*cc is the complete product
// Overlaying *cc and c[] avoids the calculation:
// ans = c[0] + (long int)256*c[1] + (long int)65536*c[2] + (long int)16777216*c[3];

		SFRPAGE = UART0_PAGE;
		printf("\r\nA: (HEX) %04X, %d,  B: (HEX) %04X, %d", *aa, *aa, *bb, *bb);
		printf("\r\nA x B Product: (HEX BYTES) %02X%02X%02X%02X", c[3],c[2],c[1],c[0]);	
		printf("\r\nA x B Product: (HEX LONG INT) %08lX, %ld", ans, ans);
		
		SFRPAGE = MAC0_PAGE;
		for(i=0; i<4; i++)	//Use the accumulator shift operation to 
							//shift the value left 4 bits (= multiply by 4)
							//This operation ignores bit overflows
		{
			MAC0CF = 0x20;	//Set shift direction left and do 1 bit shift
		}

		c[0] = MAC0ACC0;	//Get the lo 0th byte of product
		c[1] = MAC0ACC1;	//Get the mid 1st byte of product
		c[2] = MAC0ACC2;	//Get the mid 2nd byte of product
		c[3] = MAC0ACC3;	//Get the hi 3rd byte of product

		SFRPAGE = UART0_PAGE;
// *cc is the 32-bit answer and *dd is the low 16 bits of *cc
		printf("\r\nProduct<<4: (HEX LONG INT) %08lX, (DEC LO 16 BITS) %d\n", *cc, *dd);
		
	}

}
Exemplo n.º 13
0
void main()
{
	unsigned char c;

	Init_Device();

	CheckSRAMs();

	adc_select=3;
	ADCConfigEven=ADCConfigOdd=0;		// adc0 gain and channel selection for every even sample and every odd sample
	DAC0_mode=0;
	handshake=1;
	dac_increment=1;
	dac_amplitude=255;
	dac_offset=0;
	fifo_size=128;	// default number of samples in a block

//fifo_size=4;	// default number of samples in a block
//SetSamplingFreq(100);

	for(c=0; c<3; c++)	// flash the power LED three times to indicate booting
	{
		LED=0;	Delay_ms(200);
		LED=1;	Delay_ms(200);
	}
	LED=0;


	RTS=0;




	while (1)
	{
		while (SInOut()!='@');
		c=SInOut();
		if (c=='I')
		{
			SendID();
		}
		else if (c=='x')	// switch reference voltage and resistors
		{
		}
		else if (c=='t')	// set trigger polarity
		{
		}
		else if (c=='b')	// set fifo block size (number of samples in a block
		{
			fifo_size=SInOut();
		}
		else if (c=='c')	// configure continuous sampling mode
		{
			c=SInOut();
			ADCConfigEven = ((c & 1) << 4) | ((c & 2) << 2);
			c=SInOut();
			ADCConfigEven =  ((c & 1) << 5) | ((c & 2) << 5);
			c=SInOut();
			ADCConfigOdd = ((c & 1) << 4) | ((c & 2) << 2);
			c=SInOut();
			ADCConfigOdd =  ((c & 1) << 5) | ((c & 2) << 5);
		}
		else if (c=='S') // start sampling, ESC exits
		{
			ContSampling();
		}
		else if (c=='s') // start sampling, ESC exits
		{
			unsigned long n;

			n = SInOut();
			n = (n << 8)+SInOut();
			n = (n << 8)+SInOut();
			SetSamplingFreq(n);
			n = SInOut();
			n = (n << 8)+SInOut();
			HiSpeedSampling(n);
		}
		else if (c=='A') // select ADCs
		{
			adc_select = SInOut() & 3;
		}
		else if (c=='1') // set channel
		{
			c=SInOut();
			MUX1A0 = c & 1;
			MUX1A1 = c & 2;
		}
		else if (c=='2') // setchannel
		{
			c=SInOut();
			MUX2A0 = c & 1;
			MUX2A1 = c & 2;
		}
		else if (c=='M') // measure channels
		{
			c=SInOut();
			if (c<1) c=1;
			Convert(c); // make a single conversion and send data to PC
			SOut(adc1data >> 8);	// channel 0 or 1
			SOut(adc1data);
			SOut(adc0data >> 8);	// channel 2 or 3
			SOut(adc0data);
		}
		else if (c=='f') // set freq
Exemplo n.º 14
0
 ////////////////////////////////////////////////////////////////////////////
///////////////
// 函数名:
// 编写者:
// 参考资料:
// 功 能:
// 输入参数:
// 输出参数:
// 备 注:
////////////////////////////////////////////////////////////////////////////
///////////////
void main (void)
{	PCA0MD &= ~0x40;                    // Disable Watchdog timer
	Init_VAR();
	Init_Device();
	Init_patch();
	BUZZY_OFF();
	Init_sensor();
	P1MDOUT&=~0x06;	//p11 p12 非推挽	 LCD时钟数据和加密
	P1MDOUT&=~0x40;	//p16 非推挽	LCD选通
	P1MDOUT&=~0x80;	//p17 非推挽  LCD电源总开开关
	P1MDOUT&=~0x20;	//p15 非推挽	LCD选通
#ifdef	SECURE_SPI
	P0MDOUT&=~0x80;	//p07 非推挽   //加密MCLK
	P07=1;
#endif
	P0MDOUT&=~0x20;  //充满检测 ,高:充满或未冲  低:充电
	P1|=0x46;	  //srb clk data 
	PO_LCD_POWER(P_LCD_ON);
	Init_LCD();
	Init_EPROM();
#ifdef	SECURE_SPI
  {extern void InitSPICom(void) ;
	extern char TEST_SPI(char CMD_a);
	BYTE tryc=3;
	InitSPICom()  ;
	F_demo=1;
	do
	 {
		if(1==TEST_SPI(CMD_RD_ID))
		{	
		F_demo=0;
		break;
		}
		
		DelayXms(300);

	}while(tryc--)	 ;
	if(1==F_demo)
	{	
		
		DisplayCont=DISPLAY_DEMO;
		Display_All();	   //显示初始错误

	}

	}
	
#endif
	DPRINTF(printf("MAIN Program\n" ))	 ;
#if 0
	if(PI_ADJUST_DET())
	{
	  DelayXms(100);
	  if(PI_ADJUST_DET())	
	  NEW_KEY= KEY_ADJUST;
	  
	}
#endif
#if 1
	if(PWR_G2==0)
	{ 
	  	diaplay_std ();
	    DelayXms(3000);
	}
#endif
	while(1)
	{
		
	   {
//WORD i  ;extern 	  BYTE StateSensor	  ;
//     	if(StateSensor==-1)
//		LEDIO=!LEDIO;
		}
		if(F_5ms)
		{
		F_5ms=0;
	    if(PWR_G1==0)	{StateSensor=0;}
	{extern void TestACHOL();
		  TestACHOL();	
			
		}

		}
	//	if(F_10ms)
	//	{
	//		F_10ms=0;

	//	}
		if(F_50ms)
		{	F_50ms=0;
			
			Task_50ms();

			
			
		}
		if(F_100ms)
		{  
			F_100ms=0;
	/*		

		{extern void TestACHOL();
		  TestACHOL();	
			
		}
*/
		   {	
		    extern WORD CountHeat;	
		    if(CountHeat<=350)
			{
			  CountHeat++;
			} 
			}
			DO_Key_Action()	 ;
			Display_All();
			{
			extern void SendCycbuf(void);
			SendCycbuf();

			}
		    
			
		}
		if(F_200ms)
		{	 
			

			F_200ms=0; 
			
			
		}
		if(F_500ms)
		{	F_500ms=0;
			
			 
			
		}
		
		if(F_1000ms)
		{
		//	DPRINTF(printf("time=%bd \n" ,sys_time.Time_1_sec))	 ;
		 Task_500ms();
		}
		
		
	}
	
}