MCD2-DEMO digital tube display PICC-18 example (suitable for beginners)

Publisher:天涯拾遗Latest update time:2017-12-10 Source: eefocusKeywords:MCD2-DEMO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/**************************************************************
Function implemented: Make the digital tube display 0-5 from left to right on MCD2-DEMO


Chip P IC 18F452
Compiler PI CC -18


XT:4M Hz
********************************************** *******************/

#include "pic18.h"
const unsigned char display_numb[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xd8,0x80,0x90};
unsigned char display_data[6];//0:L 5:R
/******************************************************************
Port initialization
LATC as digital tube segment driver (low effective)
LATA as digital tube bit selection driver (low effective)
***************************************************************/
void init_port(void)
{
  LATC=0xff; //
  TRISC=0; //Port C is used as a digital tube segment and set to output
  ADCON1=0x07;
  TR ISA =0; //Port A is used as a digital tube bit selection control pin and set to output   
  LATA=0xff; 
}
/***********************************************************
Delay program
************************************************************/
void delay_1ms(void)
{
  unsigned int n;
  for(n=0;n<50;n++)
   {
    NOP();
   }
}
void delay_ms(unsigned int time)
{
  for(;time>0;time--)
   {
    delay_1ms();
   }
}
/**********************************************************************
The main program
displays 0-5 from left to right
*******************************************************************/
void main(void)
{
  unsigned char n;
  init_port();
  display_data[0]=display_numb[1];//2
  display_data[1]=display_numb[0];//1
  display_data[2]=display_numb[3];//4
  display_data[3]=display_numb[2];//3
  display_data[4]=display_numb[5];//6
  display_data[5]=display_numb[4];//5
  while(1)
   {
    LATA=0xfe;   
    for(n=0;n<6;n++)
     {
      LATC=display_data[n];
      delay_ms(1);
      LATA=(LATA<<1)+1;
     }
   }
}


Keywords:MCD2-DEMO Reference address:MCD2-DEMO digital tube display PICC-18 example (suitable for beginners)

Previous article:877A software simulates I2C communication to read and write 24C02
Next article:PIC microcontroller communication routine

Recommended ReadingLatest update time:2024-11-23 14:57

Using PIC microcontroller PICC programming to achieve the conversion between BCD and C code
  There are many C51 codes for DSI302, but none of them provide BCD conversion.      Here are two BCD conversion functions for the hardware characteristics of DS1302:   The total size of the two functions is only 53 bytes, which is very good.
[Microcontroller]
Using PIC microcontroller PICC programming to achieve the conversion between BCD and C code
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号