历史上的今天
返回首页

历史上的今天

今天是:2024年09月11日(星期三)

正在发生

2020年09月11日 | mickoC 编写pic18f45k22读取i2c接口RTC pcf8583时间显示在数码管

2020-09-11 来源:51hei

单片机源程序如下:

/*

* Project name:

     Seven Segment Display (The 'Hello World' example for the Seven Segment Display)

* Copyright:

     (c) Mikroelektronika, 2011.

* Revision History:

     20110929:

       - initial release (FJ);

* Description:

     This code demonstrates how to display number on one 7-segment display

     (common cathode). Display is connected to PORTD (RD0..RD7, segment A to

     RD0, segment B to RD1, etc); common cathode is connected to the pin RA0 on

     PORTA. Number is incremented every 1s.


* NOTES:

     - Turn on Seven Segment Display switches SW4.1, SW4.2, SW4.3 and SW4.4. (board specific)

*/


#include "Display_Utils.h"


//unsigned short  portd_index;


char seconds, minutes, hours, day, month, year; // Global date/time variables

char i;

// Software I2C connections

/*sbit Soft_I2C_Scl           at RC3_bit;

sbit Soft_I2C_Sda           at RC4_bit;

sbit Soft_I2C_Scl_Direction at TRISC3_bit;

sbit Soft_I2C_Sda_Direction at TRISC4_bit;

*/

// End Software I2C connections



//--------------------- Reads time and date information from RTC (PCF8583)

void Read_Time() {


  I2C1_Start();               // Issue start signal

  I2C1_Wr(0xA0);           // Address PCF8583, see PCF8583 datasheet

  I2C1_Wr(2);              // Start from address 2

  I2C1_Repeated_Start();     // issue I2C signal repeated start

  //I2C1_Start();               // Issue repeated start signal

  I2C1_Wr(0xA1);           // Address PCF8583 for reading R/W=1


  seconds = I2C1_Rd(1);     // Read seconds byte

  minutes = I2C1_Rd(1);     // Read minutes byte

  hours = I2C1_Rd(1);       // Read hours byte

  day = I2C1_Rd(1);         // Read year/day byte

  month = I2C1_Rd(0);       // Read weekday/month byte

  I2C1_Stop();                // Issue stop signal


}


//-------------------- Formats date and time

void Transform_Time() {

  seconds  =  ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F);  // Transform seconds

  minutes  =  ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F);  // Transform months

  hours    =  ((hours & 0xF0)  >> 4)*10  + (hours & 0x0F);    // Transform hours

  year     =   (day & 0xC0) >> 6;                             // Transform year

  day      =  ((day & 0x30) >> 4)*10    + (day & 0x0F);       // Transform day

  month    =  ((month & 0x10)  >> 4)*10 + (month & 0x0F);     // Transform month

}


/*

void interrupt() {

  LATD = 0;                             // Turn off all 7seg displays

  LATD = mask(hours/10u);      // bring appropriate value to PORTD

  LATA = 0b011111;                       // turn on appropriate 7seg. display

  Delay_ms(2);

  LATD=0;

  LATD = mask(hours%10u);

  LATA = 0b101111;

  Delay_ms(2);

  LATD=0;

  LATD = mask(minutes/10u);

  LATA = 0b110111;

  Delay_ms(2);

  LATD=0;

  LATD = mask(minutes%10u);

  LATA = 0b111011;

  Delay_ms(2);

  LATD=0;

  LATD = mask(seconds/10u);

  LATA = 0b111101;

  Delay_ms(2);

  LATD=0;

  LATD = mask(seconds%10u);

  LATA = 0b111110;

  Delay_ms(2);

  LATD=0;


  TMR0L  =   0;                  // reset TIMER0 value

  TMR0IF_bit = 0;                // Clear TMR0IF

} */


void main() {

  ANSELA = 0;                    // Configure PORTA pins as digital

  ANSELD = 0;                    // Configure PORTD pins as digital


  TRISA = 0;                     // Configure PORTA as output

  LATA  = 0;                     // Clear PORTA

  TRISD = 0;                     // Configure PORTD as output

  LATD  = 0;                     // Clear PORTD


  //T0CON = 0xC4;                  // Set TMR0 in 8bit mode, assign prescaler to TMR0

  //TMR0L = 0;                     // clear TMROL


  //GIE_bit = 1;

  //TMR0IE_bit = 1;


  I2C1_Init(100000);         // initialize I2C communication


  //Soft_I2C_Init();           // Initialize Soft I2C communication


  do {

     Read_Time();             // Read time from RTC(PCF8583)

     Transform_Time();        // Format date and time

     for (i=0;i<32;i++)

      {

      LATD = 0;                             // Turn off all 7seg displays

      LATD = mask(hours/10u);      // bring appropriate value to PORTD

      LATA = 0b011111;                       // turn on appropriate 7seg. display

      Delay_ms(20);

      LATD=0;

      LATD = mask(hours%10u);

      LATA = 0b101111;

      Delay_ms(20);

      LATD=0;

      LATD = mask(minutes/10u);

      LATA = 0b110111;

      Delay_ms(20);

      LATD=0;

      LATD = mask(minutes%10u);

      LATA = 0b111011;

      Delay_ms(20);

      LATD=0;

      LATD = mask(seconds/10u);

      LATA = 0b111101;

      Delay_ms(20);

      LATD=0;

      LATD = mask(seconds%10u);

      LATA = 0b111110;

      Delay_ms(20);

      LATD=0;

      }

     //Delay_ms(4000);                      // one second delay


  } while(1);                            // endless loop

}


推荐阅读

史海拾趣

Chenmoun Enterprise Ltd公司的发展小趣事

在电子行业竞争日益激烈的背景下,Chenmoun Enterprise Ltd始终坚持品质至上的原则。公司建立了严格的质量管理体系,从原材料采购到生产流程再到产品出厂,每一个环节都严格把关。这种对品质的执着追求赢得了客户的信任和口碑,使得Chenmoun的产品在市场上获得了广泛的认可。

爱特姆(ATOM)公司的发展小趣事

爱特姆科技自在美国德克萨斯州休斯顿市成立以来,便致力于电子行业的创新与发展。1998年,公司成功创立了“ATOM”品牌,标志着其正式踏入了品牌化发展的道路。起初,爱特姆以台湾、深圳、昆山为主要研发生产基地,凭借对技术的不断追求和对市场的敏锐洞察,逐渐在连接器领域取得了突破。

ACCUTEK公司的发展小趣事

随着产品质量的不断提升和市场份额的逐步扩大,ACCUTEK公司开始将目光投向国际市场。公司积极参加国际电子展会和技术交流活动,与全球多家知名企业建立了合作关系。同时,公司还在海外设立了多个分支机构,以便更好地服务当地客户。这些举措不仅提升了公司的国际影响力,也为公司的长远发展注入了新的活力。

DAYLIGHT公司的发展小趣事

随着公司规模的扩大和市场份额的增加,DAYLIGHT开始将目光投向国际市场。公司通过与国际知名电子企业的合作,成功将其产品打入国际市场,并在多个国家和地区建立了销售渠道。同时,DAYLIGHT还积极参与国际电子展和技术交流会议,不断提升其在国际市场上的知名度和影响力。

Arduino公司的发展小趣事

2005年,意大利Ivrea交互设计学院的副教授Massimo Banzi面临了一个问题:他的学生们无法负担市面上昂贵的微控制器。为了解决这个问题,Banzi与他的同事David Cuartielles开始着手制造一个更便宜、更易于使用的电子平台。他们基于学生Hernando Barragá的Wiring平台,通过拆解和重新设计,最终推出了价格仅为30美元的Arduino电路板。Arduino的名字来源于他们常去的酒吧“di Re Arduino”,以此纪念这个创新的起点。

HEIMANN公司的发展小趣事

随着物联网和智能设备的兴起,Arduino平台在智能家居、智能农业、机器人等领域的应用越来越广泛。开发者们可以利用Arduino平台来设计和开发各种智能设备和应用,实现设备的互联互通和智能化控制。这些应用不仅提高了人们的生活质量,也推动了电子行业的进步和发展。

这五个故事展示了Arduino公司在电子行业中的发展历程和取得的成就。从最初的廉价微控制器解决方案,到如今的多样化主板和广泛应用,Arduino始终秉持着创新、开放和合作的精神,为电子行业的发展做出了重要贡献。

问答坊 | AI 解惑

LED存在的疑问?

replyreload += \',\' + 376734;Timson,如果您要查看本帖隐藏内容请回复…

查看全部问答>

求硬件达人 帮忙解决一个FPGA输入的问题

//声程处理 void rangeprocess(long int nMyRange,long int nMyPDelay) { //float screenvalue; long int nTotal; long int nDiv; long int  nAverage,nResidual,temp; int i,j; //nResidualAverage,i,j; void far *pN; ...…

查看全部问答>

刚入行新人求教

刚进公司,看了几天代码感觉收获不大。 公司是做移动电话终端的,开发的都是用C/C++,功能就是用一个座机上插SIM卡,然后可以空中充值(就是帮别人缴费充值),打电话,发短信甚至上网,各位帮忙推荐点资料或者书籍看看,先谢谢!…

查看全部问答>

STM32的USB库有个宏有点问题,希望改正

USB库头文件中usb_regs.h中/******************************************************************************** Macro Name     : SetEPAddress.* Description    :  ...…

查看全部问答>

STM32库真让人哭笑不得!^_^!

/* ADC1 configuration ------------------------------------------------------*/  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;  ADC_InitStructure.ADC_ScanConvMode = E ...…

查看全部问答>

视频指挥调度系统多面助力航空运输业

2012年06月04日  中安网    随着我国航空运输的不断推进和快速发展,对我国全省各地的机场建设起着强大的推动效应,同时,也对对机场所在的城市经济社会发挥了一定的提振拉动效应。当然,随着人们对于航空行业的接受度和空中交通流 ...…

查看全部问答>

亿光过零检测光耦

本帖最后由 jameswangsynnex 于 2015-3-3 20:02 编辑 (潮光光耦网整理编辑)2012-06-06        驱动大功率交流器件时常用双向可控硅进行功率控制,根据控制方式的不同有过零控制和移相控制。不管哪种控制都要对 ...…

查看全部问答>

求一个基于51单片机的数字电流表设计

RT。。。。。。。。。。。。。。。。。。。…

查看全部问答>

codesourcery sourcery会产生 blx 0x80144c8 非法指令

我现在用CodeSourcery+jlink+openocd开发stm32 平台:stm32f103zet6 flash:内置512K(大容量) sram:内置64K+外部512K 启动文件:startup_stm32f10x_hd.c 链接脚本:stm32f10x_flash_extsram.ld 程序一执行80行的除法运算就进入硬中断,这是 ...…

查看全部问答>