µ¥Æ¬»úµÄÌØÊ⹦ÄܼĴæÆ÷SFR£¬ÊÇSRAMµØÖ·ÒѾȷ¶¨µÄSRAMµ¥Ôª£¬ÔÚCÓïÑÔ»·¾³Ï¶ÔÆä·ÃÎʹéÄÉÆðÀ´ÓÐÁ½ÖÖ·½·¨¡£
1
²ÉÓñê×¼CµÄÇ¿ÖÆÀàÐÍת»»ºÍÖ¸ÕëÀ´ÊµÏÖ
²ÉÓñê×¼CµÄÇ¿ÖÆת»»ºÍÖ¸ÕëµÄ¸ÅÄîÀ´ÊµÏÖ·ÃÎÊMCUµÄ¼Ä´æÆ÷£¬ÀýÈç:
#define DDRB (*(volatile unsigned char *)0x25)
·ÖÎöÈçÏ£º
ÕâÑù¶Á/дÒÔ0x25ΪµØÖ·µÄSRAMµ¥Ôª£¬Ö±½ÓÊéдDDRB¼´¿É£¬¼´DDRBΪ±äÁ¿£¬Ö»²»¹ý±äÁ¿µÄµØÖ·¹Ì¶¨Îª0x25¡£ÀýÈ磺
DDRB = 0xff;
ÕâÑù±ÈÖ±½Ó²ÉÓÃÖ¸Õë±äÁ¿µÄ·½·¨Ö±¹ÛºÍ·½±ãµÄ¶à£¬ÀýÈ磺
unsigned char *p, i;
p = 0x25;
i = *p; //°ÑµØַΪ0x25µ¥ÔªÖеÄÊý¾Ý¶Á³öËÍÈëi±äÁ¿
*p = 0; //ÏòµØַΪ0x25µÄµ¥ÔªÖÐдÈë0
×ܽáһϣ¬¾ÍÊÇ(*(volatile unsigned char *)0x25)¿ÉÒÔ¿´×÷ÊÇÒ»¸öÆÕͨ±äÁ¿£¬Õâ¸ö±äÁ¿Ó´¹Ì¶¨µÄµØÖ·£¬Ö¸Ïò0x25¡£¶ø0x25Ö»ÊǸö³£Á¿£¬²»ÊÇÖ¸Õ룬¸ü²»ÊDZäÁ¿¡£
2
¶ÔC±àÒëÆ÷½øÐÐÓï·¨À©³ä
¶ÔC±àÒëÆ÷½øÐÐÓï·¨À©³ä¡£ÀýÈçMCS51ϵÁÐKeilCÖÐÀ©³äsfr¹Ø¼ü×Ö£¬¾ÙÀýÈçÏ£º
sfr P0 = 0x80;
ÕâÑù²Ù×÷0x80µ¥ÔªÖ±½ÓдP0¼´¿É¡£
ÏÂÃæ¶ÔAVRµÄ¸èC±àÒëÆ÷¶Ô·ÃÎÊMCU¼Ä´æÆ÷µÄ·½·¨½øÐмò½é¡£
A£º²ÉÓñê×¼CµÄÇ¿ÖÆÀàÐÍת»»ºÍÖ¸ÕëÀ´ÊµÏÖ·ÃÎÊMCUµÄ¼Ä´æÆ÷£¬Ã¿Ò»¸öC±àÒëÆ÷¶¼Ö§³Ö£¬ÔÒòºÜ¼òµ¥£¬ÕâÊDZê×¼C¡£
B£ºICCAVRºÍGCCAVRûÓж¨ÒåеÄÊý¾ÝÀàÐÍ£¬Ö»ÄܲÉÓñê×¼CµÄÇ¿ÖÆÀàÐÍת»»ºÍÖ¸ÕëÀ´ÊµÏÖ·ÃÎÊMCUµÄ¼Ä´æÆ÷¡£¶øIARºÍCodeVisionAVR±àÒëÆ÷¶ÔANSI C½øÐÐÁËÀ©³ä£¬¶¼¶¨ÒåÁËеÄÊý¾ÝÀàÐÍ£¬ÊÇCÓïÑÔ¿ÉÒÔÖ±½Ó·ÃÎÊMCUµÄÓйؼĴæÆ÷£¬ÀýÈ磬IARÖУº
SFR_B(DDRB, 0x28)
CodeVisionAVRÖУº
sfrb DDRB = 0x28
ÕâÑù,PORTB=0xff;µÈͬÓÚ(*(volatile unsigned char *)0x05) = 0xff;¶ø0x25ÕýºÃÊǼĴæÆ÷PORTBÔÚÆ÷¼þATmega48/88/168ÖеĵØÖ·¡£
GCCAVRÿ¸öAVRÆ÷¼þÔÚÍ·Îļþ²»²ÉÓÃÖ±½Ó¶¨ÒåÌØÊ⹦ÄܼĴæÆ÷ºê£¬ÀýÈçÔÚiomx8.hÎļþÖÐÒ»¸ö¶¨ÒåÈçÏ£º
#define PORTB _SFR_IO8(0x25)
¶øÔÚsfr_defs.hÖпÉÒÔÕÒµ½ÈçÏÂÁ½¸öºê¶¨Ò壺
#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr)+0x20)
#define _MMIO_BYTE(mem_addr) (*(volatile unit8_t *)(mem_addr))
ʵÖÊÉÏÓëÖ±½ÓµÄÇ¿ÖÆÀàÐÍת»»ºÍÖ¸Õ붨ÒåÊÇÒ»ÑùµÄ¡£
ÁíÍ⣬GCCAVRÖкê_BV(bit)ÊDzÙ×÷I/O¼Ä´æÆ÷ÊÇƵ·±Óõ½µÄ£¬avr-libc½¨ÒéʹÓÃÕâÒ»ºê½øÐмĴæÆ÷µÄλ²Ù×÷£¬ËûÔÚÎļþsfr_defs.hÖж¨ÒåÈçÏ£º
#define _BV(bit)
ÒÔÏÂÊÇËûµÄʹÓÃʾÀý£º
DDRB = _BV(PB0) | _BV(PB1); //Æ÷¼þÍ·ÎļþÖÐÒѾ¶¨ÒåPB0´ú±í0£¬PB1´ú±í1
ËûµÈͬÓÚ¡°DDRB=0x03;¡±,ÕâÑùдµÄÄ¿µÄÊÇΪÁËÌṩ³ÌÐòµÄ¿É¶ÁÐÔ¡£²»Òªµ£ÐÄËü»áÉú³É±È¡°DDRB=0x03;¡±¸ü´óµÄ´úÂ룬±àÒëÆ÷»á´¦ÀíÕâÖÖÊÂÇ飬×îÖÕ»áÊä³öÓë¡°DDRB=0x03;¡±Í¬ÑùµÄ½á¹û¡£