ATmega 168 asm needs more help!

Why won’t the following simple routine work? Please read my last post if more background info is needed. The MPU is a baby “O”, and most of the code, either “C” or snippits of embedded “asm” work perfectly. The “sbic” instruction in the test code below, should test PB4 and skip the “cbi” instruction if PB4 is grounded, thus extending the pulse depending on the number of nop’s. It does not matter whether PB4 is at 5V or ground, no change is noted. Comment the “cbi” instruction, and eurika, the pulse width increases.

#define F_CPU 20000000UL
#include <stdio.h>
#include <util/delay.h>
#include <avr/io.h>

int main(void) {
  DDRB = 0x20;                             // Set PORTB data dirction register for PB5

  while(1) {
    PORTB |= 0x20;
    PORTB &= ~0x20;		// Scope sync pulse. (PB5)


	asm(" sbi 5,5");		// Assembly instruction that also sets PB5 high. 
             asm(" sbic 5,4");		// Should test PB4 and skip if zero!  (won't work)
	asm(" cbi 5.5");                 // Comment this instruction and the pulse width
                                                    // will extend by about .25 microseconds.
	asm(" nop");
	asm(" nop");
	asm(" nop");
	asm(" nop");		// If PB4 is zero, the pulse should be extended.

	asm(" cbi 5,5");		// Clear PB5.
	_delay_ms(.1);
  }				// End of "while".
}				// End of "main".

Hello.

Digital I/O on the mega168 is controlled using three registers per port:

  1. DDRx: Data Direction Register for port x, used for designating a pin as a digital input or output
  2. PORTx: used for specifying the output state of port x output pins or enabling/disabling the internal 5 V pull-up on input pins
  3. PINx: used for reading the input value of port x pins

I have only very briefly looked at your code so this is not necessarily an exhaustive error list, but here are two problems I see right off the bat:

asm(" cbi 5.5"); should be asm(" cbi 5,5");
asm(" sbic 5,4"); should be asm(" sbic 3,4");

You want to test the input value of pin PB4, so you need to check bit 4 of PINB (address 0x03), not PORTB (address 0x05).

- Ben