英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流

标题: 用MPLAB对PIC16F84编程 [打印本页]

作者: winnie    时间: 2009-5-18 13:55
标题: 用MPLAB对PIC16F84编程
用MPLAB对PIC16F84编程,PORTA做开关,PORTB做LEDS,用开关控制灯的闪烁,PORTA和PORTB都用。一个简单的程序仅是供参考

/*----------------------------------------------------------------------
           This program is the demonstrate for PIC16C77 with picc16
       and ELSE conditional assembly block providing an alternative
       path of assembly code for the Microchip type.
            When the user uses which Microchip Microcontrol,he will
       define set of this Microchip type in the P16XX.EQU file. And he
       assemble source code of this type by the Microchip MPASM assem-
       bler. Exemple the chip type is PIC16C74, P74 must define as 1
       and the other types define as 0 in the P16XX.EQU file.It is the
       following:
-----------------------------------------------------------------------
*/
#include  <pic.h>
#include  "delay.h"
#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
static bit btnRtcc @ PORTBIT(PORTA,4);

void
DelayMs(unsigned char cnt)
{
#if XTAL_FREQ <= 2MHZ
do {
  DelayUs(996);
} while(--cnt);
#endif
#if    XTAL_FREQ > 2MHZ
unsigned char i;
do {
  i = 4;
  do {
   DelayUs(200);
  } while(--i);
} while(--cnt);
#endif
}

main(void)
{
unsigned char i,j;
static const unsigned char codeled[17] =
                     {0x21,0x7D,0x32,0x38,0x6c,0x0A8,0x0A0,0x3D,0x20,0x28,
                      0x24,0x0E0,0x0A3,0x70,0x0A2,0xA6,0x00};
static const unsigned char codeledE[17] =
                     {0x0,0x3,0x1,0x1,0x2,0x04,0x04,0x1,0x0,0x0,
                      0x0,0x06,0x04,0x3,0x04,0x4,0x00};

TRISA = 0x10;   /* RA4=sw_RTCC input other bits output */
TRISB = 0x00;   /* RB0=sw_INT input other bits output */
TRISC = 0;    /* all bits output */
TRISD = 0;
TRISE = 0;
j = 0;
for(;;)
{
for(j=0;j<17;j++)
  {
  if(btnRtcc==0) break;
  PORTA = codeled[j];
  PORTB = codeled[j];
  PORTC = codeled[j];
  PORTD = codeled[j];
  PORTE = codeledE[j];
  DelayMs(200);  /* output value of j */
  }
  for(j=0;j<17;j++)
  {
      PORTA = codeled[j];
      PORTE=codeledE[j];
      DelayMs(500);
  }
  for(j=0;j<17;j++)
  {
      PORTB = codeled[j];
      DelayMs(500);
  }
  for(j=0;j<17;j++)
  {
      PORTC = codeled[j];
      DelayMs(500);
  }
  for(j=0;j<17;j++)
  {
      PORTD = codeled[j];
      DelayMs(500);
  }
  
}
}





欢迎光临 英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 (http://enroobbs.com/) Powered by Discuz! X3.2