Пример #1
0
int main(void)
{
	unsigned char k;
	init();
	Buffer_USART_Tx_String("End Init \r");
	while(1)
	{		
		if(Need_Receiving==ON)
		{
			if( ((PINC)&(1<<PINC0))==0 )
			{
				if(Receiving==OFF && Compteur_Data_Received!=10)
				{
					Receiving = ON;	// indique que la récéption est en cour
					Compteur_Timer = 0;
					TIMER0_START();	// Lance le timer0 
				}
				else asm("nop");
			}
			else asm("nop");	
			Need_Receiving=OFF;	
		}
		if(RX600INTREQUEST==ON)
		{
			Received_600_baud(); // permet de gérer le nombre d'incrémentation du timer 0 en mode de réception de donnée
			RX600INTREQUEST=OFF;
		}
		if(TX600INTREQUEST==ON)
		{
			Send_600_baud(); // permet de gérer le nombre d'incrémentation du timer 0 en mode d'envoi de donnée
			TX600INTREQUEST=OFF;
		}
		if(Compteur_Data_Received != 0) 
		{
			putchar_Buffer(Data_Received[0]);
			for(k=0;k<=10;k++) 
			{
				Data_Received[k]=Data_Received[k+1];
			}
			Data_Received[10]=0x00;
			Compteur_Data_Received--;
		}
		if (Rx_Counter != 0 && Sending == 0)
		{
			c = getchar_Buffer ();
			chartobit (c, tableau);
			
			Sending = ON;
			TCNT2 = 0;

			OCR1A = valeurf2;
			TIMER2_START();
			Index = 0;
			cbiBF (PORTB, PINB0);
		}
	}
}
Пример #2
0
void
pack(const char *input, const char *output)
{
#ifdef STAT
	clock_t time1, time2;
	time1 = clock();
#endif
	int c, i, j;

	FILE *infile = fopen(input, "r");
	assert(infile);

	int size = ptablebuild(infile, ptable);

	encode(0, size - 1);

	printf("code table size: %d\n", size);

#ifdef STAT
	FILE *codetable = fopen("codetable", "wb");
	assert(codetable);
	for (i = 0; i < size; ++i)
		{
			fprintf(codetable, "%c %s %f \n", ptable[i].ch, codes[ptable[i].ch], ptable[i].p);
			printf("%c->%s\n", ptable[i].ch, codes[ptable[i].ch]);
		}
	fclose(codetable);
#endif
	
	for (i = 0; i < size; ++i)
		printf("%c->%s\n", ptable[i].ch, codes[ptable[i].ch]);
	
	FILE *outfile = fopen(output, "wb");
	assert(outfile);
	
	putc(size - 1, outfile);

	buffer buff;
	buff.size = buff.v = 0;

	char codesize[8], codebit[8], *ch;
	for (i = 0; i < size; ++i)
		{
			c = ptable[i].ch;
			chartobit(c, codebit);
			for (j = 0; j < 8; ++j)
				writebit(outfile, &buff, codebit[j]); // 8 bits of the code

			chartobit(strlen(codes[c]) - 1, codesize);
			for (j = 0; j < 8; ++j)
				writebit(outfile, &buff, codesize[j]); // size of code
			
			j = -1;
			ch = codes[c];
			while (ch[++j] != '\0')
				writebit(outfile, &buff, ch[j]); // code
		}

	fseek(infile, 0, SEEK_SET);
	
	while ((c = getc(infile)) != EOF)
		{
			ch = codes[c];
			j = -1;
			while (ch[++j] != '\0')
				writebit(outfile, &buff, ch[j]);
		}
	if (buff.size != 8)
		putc(buff.v, outfile);
	
	putc(buff.size, outfile);

	fclose(outfile);
	fclose(infile);

#ifdef STAT
	time2 = clock();
	printf("time:%f\n", (double)(time2 - time1) / (double)CLOCKS_PER_SEC);
#endif
}