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

 找回密码
 立即注册
搜索
电子烟方案单片机单片机开发深圳单片机开发
单片机方案国产单片机8位单片机电子烟方案开发
查看: 2820|回复: 0
打印 上一主题 下一主题

用MPLAB对PIC16F84编程

[复制链接]
跳转到指定楼层
1#
发表于 2009-5-18 13:55:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
用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);
  }
  
}
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|公司首页|Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 ( 粤ICP备09008620号 )

GMT+8, 2024-11-27 23:08 , Processed in 0.054187 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表