Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] accessing bits (e.g. of ports)

2005-01-31 by Mike Perks

Stefan,

I have been following this thread with interest so let me throw in my 2 
cents.

Different program languages and assembly languages have different pros 
and cons. Some make life easier generally at the expense of abstracting 
away detail. Without trying to over generalize here, programming in C is 
very close to programming in assembler although it does save quite a bit 
of work in other places. I just want to highlight to this group that 
there are other alternatives such as BasicX and BasCom for AVR chips.

As you can see from my email id I have become quite a fan of BasicX and 
you may also find that it is more productive than what you are using 
now. Here is the BasicX equivalent for what you wanted to do:

Const Motor_Enable_Pin as Byte = 22
Const Turn_Motor_On as Byte = bxOutputHigh
Const Turn_Motor_Off as Byte = bxOutputLow
...
Sub Main()
...
    call PutPin(Motor_Enable_Pin, Turn_Motor_On)
...
End Sub

Regards,
Mike


 Trethan wrote:

>On Mon, 31 Jan 2005 09:47:49 -0500 (EST), <ethan@bufbotics.org> wrote:
>
>  
>
>><code>
>>if (turn_motor_on) {
>>   setbit(MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN);
>>} else {
>>   clrbit(MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN);
>>}
>></code>
>>Personally, I would prefer something like.....
>><code>
>>write_bit(turn_motor_on, MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN);
>></code>
>>    
>>
>
>You could make that with a define i think. I guess even i could figure out  
>how eventually.
>
>But well, wouldn't it be great if one could just write
>
>MOTOR_ENABLE_PIN = turn motor on;
>
>or, if need be
>
>MOTOR_ENABLE_PORT.MOTOR_ENABLE_BIT = turn motor on;
>
>
>I have the same situation here.
>I don't understand why that doesn't work. I'm no programmer as everyone  
>sees easily, but when reading various stuff i get the impression "well, if  
>you don't use bit operations you aren't a proper programmer, get lost.".  
>That might well be true, and i'm not a proper programmer, but i still  
>don't understand why i must fight with &|!<< to change or read a single  
>bit.
>I mean, life is hard enough, why make it any harder?
>
>
>Why exactly is't a bit just a variable like for example PORTB?
>I can write PORTB=0xFF; but can't do the same with bits.
>
>ST
>
>  
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.