C51 COMPILER V9.59.0.0 APP_I2C_PS 06/10/2021 10:21:37 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE APP_I2C_PS OBJECT MODULE PLACED IN .\list\APP_I2C_PS.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE ..\App\src\APP_I2C_PS.c LARGE OMF2 OPTIMIZE(8,SPEED) BROWSE INCDIR(..\Dr -iver\inc;..\User;..\App\inc) DEBUG PRINT(.\list\APP_I2C_PS.lst) TABS(2) OBJECT(.\list\APP_I2C_PS.obj) line level source 1 /*---------------------------------------------------------------------*/ 2 /* --- STC MCU Limited ------------------------------------------------*/ 3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/ 4 /* --- Mobile: (86)13922805190 ----------------------------------------*/ 5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/ 6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/ 7 /* --- Web: www.STCMCU.com --------------------------------------------*/ 8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/ 9 /* --- QQ: 800003751 -------------------------------------------------*/ 10 /* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */ 11 /*---------------------------------------------------------------------*/ 12 13 #include "APP.h" 14 #include "STC8A_GPIO.h" 15 #include "STC8A_I2C.h" 16 #include "STC8A_Soft_I2C.h" 17 #include "STC8A_NVIC.h" 18 #include "STC8A_Switch.h" 19 20 /************* 功能说明 ************** 21 22 内部集成I2C串行总线控制器做从机模式,SCL->P3.2, SDA->P3.3; 23 IO口模拟I2C做主机模式,SCL->P0.0, SDA->P0.1; 24 通过外部飞线连接 P0.0->P3.2, P0.1->P3.3,实现I2C自发自收功能。 25 26 用STC的MCU的IO方式驱动8位数码管。 27 使用Timer0的16位自动重装来产生1ms节拍,程序运行于这个节拍下,用户修改MCU主时钟频率时,自动定时于1ms. 28 计数器每秒钟加1, 计数范围为0~9999. 29 30 显示效果为: 上电后主机每秒钟发送一次计数数据,并在左边4个数码管上显示发送内容;从机接收到数据后在右边4个数 -码管显示。 31 32 下载时, 选择时钟 24MHz (可以在配置文件"config.h"中修改). 33 34 ******************************************/ 35 36 //======================================================================== 37 // 本地常量声明 38 //======================================================================== 39 40 41 //======================================================================== 42 // 本地变量声明 43 //======================================================================== 44 45 u8 temp[4]; //通用数组 46 47 //======================================================================== 48 // 本地函数声明 49 //======================================================================== 50 51 52 //======================================================================== 53 // 外部函数和变量声明 C51 COMPILER V9.59.0.0 APP_I2C_PS 06/10/2021 10:21:37 PAGE 2 54 //======================================================================== 55 56 57 //======================================================================== 58 // 函数: I2C_PS_init 59 // 描述: 用户初始化程序. 60 // 参数: None. 61 // 返回: None. 62 // 版本: V1.0, 2020-09-25 63 //======================================================================== 64 void I2C_PS_init(void) 65 { 66 1 u8 i; 67 1 I2C_InitTypeDef I2C_InitStructure; 68 1 69 1 P0_MODE_IO_PU(GPIO_Pin_0 | GPIO_Pin_1); //P0.0,P0.1 设置为准双向口 70 1 P3_MODE_IO_PU(GPIO_Pin_3); //P3.3 设置为准双向口 71 1 P6_MODE_IO_PU(GPIO_Pin_All); //P6 设置为准双向口 72 1 P7_MODE_IO_PU(GPIO_Pin_All); //P7 设置为准双向口 73 1 I2C_SW(I2C_P33_P32); //I2C_P14_P15,I2C_P24_P25,I2C_P33_P32 74 1 75 1 I2C_InitStructure.I2C_Mode = I2C_Mode_Slave; //主从选择 I2C_Mode_Master, I2C_Mode_Slave 76 1 I2C_InitStructure.I2C_Enable = ENABLE; //I2C功能使能, ENABLE, DISABLE 77 1 I2C_InitStructure.I2C_SL_MA = ENABLE; //使能从机地址比较功能, ENABLE, DISABLE 78 1 I2C_InitStructure.I2C_SL_ADR = 0x2d; //从机设备地址, 0~127 (0x2d<<1 = 0x5a) 79 1 I2C_Init(&I2C_InitStructure); 80 1 NVIC_I2C_Init(I2C_Mode_Slave,I2C_ESTAI|I2C_ERXI|I2C_ETXI|I2C_ESTOI,Priority_0); //主从模式, I2C_Mode_Mast -er, I2C_Mode_Slave; 中断使能, I2C_ESTAI/I2C_ERXI/I2C_ETXI/I2C_ESTOI/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priori -ty_2,Priority_3 81 1 82 1 display_index = 0; 83 1 DisplayFlag = 0; 84 1 for(i=0; i<8; i++) LED8[i] = 0x10; //上电消隐 85 1 } 86 87 //======================================================================== 88 // 函数: Sample_I2C_PS 89 // 描述: 用户应用程序. 90 // 参数: None. 91 // 返回: None. 92 // 版本: V1.0, 2020-09-25 93 //======================================================================== 94 void Sample_I2C_PS(void) 95 { 96 1 DisplayScan(); 97 1 98 1 if(DisplayFlag) 99 1 { 100 2 DisplayFlag = 0; 101 2 LED8[4] = I2C_Buffer[0]; 102 2 LED8[5] = I2C_Buffer[1]; 103 2 LED8[6] = I2C_Buffer[2]; 104 2 LED8[7] = I2C_Buffer[3]; 105 2 } 106 1 107 1 if(++msecond >= 1000) //1秒到 108 1 { 109 2 msecond = 0; //清1000ms计数 110 2 second++; //秒计数+1 111 2 if(second >= 10000) second = 0; //秒计数范围为0~9999 112 2 113 2 temp[0] = second / 1000; C51 COMPILER V9.59.0.0 APP_I2C_PS 06/10/2021 10:21:37 PAGE 3 114 2 temp[1] = (second % 1000) / 100; 115 2 temp[2] = (second % 100) / 10; 116 2 temp[3] = second % 10; 117 2 LED8[0] = temp[0]; 118 2 LED8[1] = temp[1]; 119 2 LED8[2] = temp[2]; 120 2 LED8[3] = temp[3]; 121 2 122 2 SI2C_WriteNbyte(0, temp, 4); 123 2 } 124 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 313 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = 4 6 PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = ---- ---- EDATA SIZE = ---- ---- HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)