- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 MPLAB X IDE 3.60 中开发一个项目。其中有一些 union/结构定义。它们用于驱动7段LCD。
我无法使用变量名称将变量传递给另一个变量。它会分配一个随机值。但是,我可以将值本身分配给相关变量,并且 LCD 可以正常工作。
main.c
#define _XTAL_FREQ 40000000
#if defined(__XC)
#include <xc.h> /* XC8 General Include File */
#elif defined(HI_TECH_C)
#include <htc.h> /* HiTech General Include File */
#elif defined(__18CXX)
#include <p18cxxx.h> /* C18 General Include File */
#endif
#if defined(__XC) || defined(HI_TECH_C)
#include <stdint.h> /* For uint8_t definition */
#include <stdbool.h> /* For true/false definition */
#endif
#include "system.h" /* System funct/params, like osc/peripheral config */
#include "user.h" /* User funct/params, such as InitApp */
#include "lcd_driver.h"
//CONFIG
#pragma config SOSCSEL = DIG
#pragma config FOSC = HS1 // Oscillator (HS oscillator (Medium power, 4 MHz - 16 MHz))
#pragma config PLLCFG = ON // PLL x4 Enable bit (Enabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF // Internal External Oscillator Switch Over Mode (Disabled)
void main(void)
{
/* Configure the oscillator for the device */
ConfigureOscillator();
//Variables
ANCON2 = 0x00;
CCP6OD = 0; // RG3, comparator disabled.
OSCCONbits.SCS = 0;
LcdInit();
LCD_7SEG();
LCD_Update();
while(1)
{
}
}
lcd_driver.c
#include <xc.h>
#include "lcd_driver.h"
#include "defines.h"
#include <string.h>
#include <stdio.h>
volatile StructLCD MediumLCDBuffer; // Not used yet
volatile StructLCD MediumLCD @0xF66;
volatile UDigit UpdatedDigit;
void LcdInit(void)
{
// Init ports function for LCD driver
LCDSE0bits.SE00 = 1;
LCDSE0bits.SE01 = 1;
LCDSE0bits.SE02 = 1;
LCDSE0bits.SE03 = 1;
LCDSE0bits.SE04 = 1;
LCDSE0bits.SE05 = 1;
LCDSE0bits.SE06 = 1;
LCDSE0bits.SE07 = 1;
LCDSE1bits.SE08 = 1;
LCDSE1bits.SE09 = 1;
LCDSE1bits.SE10 = 1;
LCDSE1bits.SE11 = 1;
LCDSE1bits.SE12 = 1;
LCDSE1bits.SE13 = 1;
LCDSE1bits.SE14 = 1;
LCDSE1bits.SE15 = 1;
LCDSE2bits.SE18 = 1;
LCDSE2bits.SE19 = 1;
LCDSE2bits.SE20 = 1;
LCDSE2bits.SE21 = 1;
LCDSE2bits.SE22 = 1;
LCDSE2bits.SE23 = 1;
LCDSE3bits.SE24 = 1;
LCDSE3bits.SE25 = 1;
LCDSE3bits.SE26 = 1;
LCDSE3bits.SE29 = 1;
LCDSE3bits.SE29 = 1;
LCDSE3bits.SE30 = 1;
// Reference ladder interval control
LCDRLbits.LRLAT0 = 1;
LCDRLbits.LRLAT1 = 1;
LCDRLbits.LRLAT2 = 1;
// Reference ladder A Power Control
LCDRLbits.LRLAP0 = 1;
LCDRLbits.LRLAP1 = 1;
// Reference ladder B Power Control
LCDRLbits.LRLBP0 = 1;
LCDRLbits.LRLBP1 = 1;
// Select internal bias
LCDREFbits.VLCD1PE = 0;
LCDREFbits.VLCD2PE = 0;
LCDREFbits.VLCD3PE = 0;
// Enable internal reference
LCDREFbits.LCDIRE = 1;
// Select internal reference source (VDD)
LCDREFbits.LCDIRS = 0;
// Select LCD contrast (0 = Max contrast, 7 = min contrast)
LCDREFbits.LCDCST0 = 1;
LCDREFbits.LCDCST1 = 0;
LCDREFbits.LCDCST2 = 0;
/* LCDCON register */
LCDCONbits.LCDEN = 1; //Enable LCD Module
LCDCONbits.SLPEN = 0;
LCDCONbits.WERR = 0;
LCDCONbits.CS = 0; // (Fosc/4)/8192))
LCDCONbits.LMUX = 3; // <1:0> 1/4 COM, 1/3 BIAS
/* LCDPS register */
LCDPSbits.WFT = 0; // Type-A Waveform Selection.
LCDPSbits.BIASMD = 0;
LCDPSbits.LCDA = 1;
LCDPSbits.WA = 0;
// LCD prescaler bits
LCDPSbits.LP0 = 1;
LCDPSbits.LP1 = 1;
LCDPSbits.LP2 = 0; // 1:4
LCDPSbits.LP3 = 0;
}
void LCD_7SEG(void)
{
unsigned char buffer = 0x12; // assign a value
//printf("%u", (unsigned char) buffer); // Does not work without this line, It assigns random value instead of buffer value
UpdatedDigit.DigitChar = buffer;
}
void LCD_Update(void)
{
MediumLCD.Seg10A = UpdatedDigit.DigitBit.SEG_A; MediumLCD.Seg10B = UpdatedDigit.DigitBit.SEG_B;
MediumLCD.Seg10C = UpdatedDigit.DigitBit.SEG_C; MediumLCD.Seg10D = UpdatedDigit.DigitBit.SEG_D;
MediumLCD.Seg10E = UpdatedDigit.DigitBit.SEG_E; MediumLCD.Seg10F = UpdatedDigit.DigitBit.SEG_F;
MediumLCD.Seg10G = UpdatedDigit.DigitBit.SEG_G;
}
lcd_driver.h
#ifndef LCD_DRIVER_H
#define LCD_DRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
typedef struct
{
// -- COM 3 (LCD)-- //) PIC(No) | LCD(no))
unsigned char ECOLOWER :1; //Seg0 LCD1
unsigned char Seg5D :1; //Seg1 LCD2
unsigned char DP5 :1; //Seg2 LCD3
unsigned char Seg6D :1; //Seg3 LCD4
unsigned char DP6 :1; //Seg4 LCD5
unsigned char Seg7D :1; //Seg5 LCD6
unsigned char DEGLOWER :1; //Seg6 LCD7
unsigned char ECOUPPER :1; //Seg7 LCD8 (LCD9 -> SEG30)
unsigned char DP7 :1; //Seg8 LCD10
unsigned char Seg9D :1; //Seg9 LCD11
unsigned char DP8 :1; //Seg10 LCD12
unsigned char Seg10D :1; //Seg11 LCD13 (LCD14 -> SEG29)
unsigned char kW :1; //Seg12 LCD15
unsigned char BarFrame_09 :1; //Seg13 LCD16
unsigned char BarGraph_I5 :1; //Seg14 LCD17
unsigned char BarFrame_I5 :1; //Seg15 LCD18
unsigned char Dummy1 :1; //Seg16 Disabled!
unsigned char Dummy2 :1; //Seg17 Disabled!
unsigned char Seg4B :1; //Seg18 LCD19
unsigned char Seg4A :1; //Seg19 LCD20
unsigned char Seg3B :1; //Seg20 LCD21
unsigned char Seg3A :1; //Seg21 LCD22
unsigned char Seg2B :1; //Seg22 LCD23
unsigned char Seg2A :1; //Seg23 LCD24
unsigned char Seg1B :1; //Seg24 LCD25
unsigned char Seg1A :1; //Seg25 LCD26
unsigned char Service :1; //Seg26 LCD27
unsigned char Dummy3 :1; //Seg27 Disabled
unsigned char Dummy4 :1; //Seg28 Disabled
unsigned char DummyNC :1; //Seg29 LCD14
unsigned char Seg8D :1; //Seg30 LCD9
unsigned char Dummy5 :1; //Seg31 Disabled
unsigned char Dummy6 :8; //LCDDATA4 not available
unsigned char Dummy7 :8; //LCDDATA5 not available
// -- COM 2 (LCD)-- //) PIC(No) | LCD(no))
unsigned char COD :1; //Seg0 LCD1
unsigned char Seg5E :1; //Seg1 LCD2
unsigned char Seg5C :1; //Seg2 LCD3
unsigned char Seg6E :1; //Seg3 LCD4
unsigned char Seg6C :1; //Seg4 LCD5
unsigned char Seg7E :1; //Seg5 LCD6
unsigned char Seg7C :1; //Seg6 LCD7
unsigned char VAL :1; //Seg7 LCD8 (LCD9 -> SEG30)
unsigned char Seg8C :1; //Seg8 LCD10
unsigned char Seg9E :1; //Seg9 LCD11
unsigned char Seg9C :1; //Seg10 LCD12
unsigned char Seg10E :1; //Seg11 LCD13 (LCD14 -> SEG29)
unsigned char Lmin :1; //Seg12 LCD15
unsigned char BarFrame_I9 :1; //Seg13 LCD16
unsigned char BarFrame_I6 :1; //Seg14 LCD17
unsigned char BarGraph_I6 :1; //Seg15 LCD18
unsigned char Dummy8 :1; //Seg16 Disabled!
unsigned char Dummy9 :1; //Seg17 Disabled!
unsigned char Seg4G :1; //Seg18 LCD19
unsigned char Seg4F :1; //Seg19 LCD20
unsigned char Seg3G :1; //Seg20 LCD21
unsigned char Seg3F :1; //Seg21 LCD22
unsigned char Seg2G :1; //Seg22 LCD23
unsigned char Seg2F :1; //Seg23 LCD24
unsigned char Seg1G :1; //Seg24 LCD25
unsigned char Seg1F :1; //Seg25 LCD26
unsigned char WaterDrop :1; //Seg26 LCD27
unsigned char Dummy10 :1; //Seg27 Disabled
unsigned char Dummy11 :1; //Seg28 Disabled
unsigned char Seg10C :1; //Seg29 LCD14
unsigned char Seg8E :1; //Seg30 LCD9
unsigned char Dummy12 :1; //Seg31 Disabled
unsigned char Dummy13 :8; //LCDDATA10 not available
unsigned char Dummy14 :8; //LCDDATA11 not available
// -- COM 1 (LCD)-- //) PIC(No) | LCD(no)
unsigned char TAP :1; //Seg0 LCD1
unsigned char Seg5F :1; //Seg1 LCD2
unsigned char Seg5G :1; //Seg2 LCD3
unsigned char Seg6F :1; //Seg3 LCD4
unsigned char Seg6G :1; //Seg4 LCD5
unsigned char Seg7F :1; //Seg5 LCD6
unsigned char Seg7G :1; //Seg6 LCD7
unsigned char Radiator :1; //Seg7 LCD8 (LCD9 -> SEG30)
unsigned char Seg8G :1; //Seg8 LCD10
unsigned char Seg9F :1; //Seg9 LCD11
unsigned char Seg9G :1; //Seg10 LCD12
unsigned char Seg10F :1; //Seg11 LCD13 (LCD14 -> SEG29)
unsigned char RPM :1; //Seg12 LCD15
unsigned char Flame :1; //Seg13 LCD16
unsigned char BarGraph_I7 :1; //Seg14 LCD17
unsigned char BarFrame_I7 :1; //Seg15 LCD18
unsigned char Dummy15 :1; //Seg16 Disabled!
unsigned char Dummy16 :1; //Seg17 Disabled!
unsigned char Seg4C :1; //Seg18 LCD19
unsigned char Seg4E :1; //Seg19 LCD20
unsigned char Seg3C :1; //Seg20 LCD21
unsigned char Seg3E :1; //Seg21 LCD22
unsigned char Seg2C :1; //Seg22 LCD23
unsigned char Seg2E :1; //Seg23 LCD24
unsigned char Seg1C :1; //Seg24 LCD25
unsigned char Seg1E :1; //Seg25 LCD26
unsigned char Phone :1; //Seg26 LCD27
unsigned char Dummy17 :1; //Seg27 Disabled
unsigned char Dummy18 :1; //Seg28 Disabled
unsigned char Seg10G :1; //Seg29 LCD14
unsigned char Seg8F :1; //Seg30 LCD9
unsigned char Dummy19 :1; //Seg31 Disabled
unsigned char Dummy20 :8; //LCDDATA16 not available
unsigned char Dummy21 :8; //LCDDATA17 not available
// -- COM 0 (LCD)-- //) PIC(No) | LCD(No))
unsigned char Line :1; //Seg0 LCD1
unsigned char Seg5A :1; //Seg1 LCD2
unsigned char Seg5B :1; //Seg2 LCD3
unsigned char Seg6A :1; //Seg3 LCD4
unsigned char Seg6B :1; //Seg4 LCD5
unsigned char Seg7A :1; //Seg5 LCD6
unsigned char Seg7B :1; //Seg6 LCD7
unsigned char Dummy22 :1; //Seg7 LCD8 (LCD9 -> SEG30)
unsigned char Seg8B :1; //Seg8 LCD10
unsigned char Seg9A :1; //Seg9 LCD11
unsigned char Seg9B :1; //Seg10 LCD12
unsigned char Seg10A :1; //Seg11 LCD13 (LCD14 -> SEG29)
unsigned char DEGUPPER :1; //Seg12 LCD15
unsigned char Dummy23 :1; //Seg13 LCD16
unsigned char BarFrame_I8 :1; //Seg14 LCD17
unsigned char BarGraph_I8 :1; //Seg15 LCD18
unsigned char Dummy24 :1; //Seg16 Disabled!
unsigned char Dummy25 :1; //Seg17 Disabled!
unsigned char BAR :1; //Seg18 LCD19
unsigned char Seg4D :1; //Seg19 LCD20
unsigned char DP4 :1; //Seg20 LCD21
unsigned char Seg3D :1; //Seg21 LCD22
unsigned char DP2 :1; //Seg22 LCD23
unsigned char Seg2D :1; //Seg23 LCD24
unsigned char DP1 :1; //Seg24 LCD25
unsigned char Seg1D :1; //Seg25 LCD26
unsigned char DP3 :1; //Seg26 LCD27
unsigned char Dummy26 :1; //Seg27 Disabled
unsigned char Dummy27 :1; //Seg28 Disabled
unsigned char Seg10B :1; //Seg29 LCD14
unsigned char Seg8A :1; //Seg30 LCD9
unsigned char Dummy28 :1; //Seg31 Disabled
unsigned char Dummy29 :8; //LCDDATA22 not available
unsigned char Dummy30 :8; //LCDDATA23 not available
} StructLCD;
typedef struct
{
unsigned char SEG_A :1;
unsigned char SEG_B :1;
unsigned char SEG_C :1;
unsigned char SEG_D :1;
unsigned char SEG_E :1;
unsigned char SEG_F :1;
unsigned char SEG_G :1;
unsigned char NONE :1;
}DGSeg;
typedef union
{
unsigned char DigitChar;
DGSeg DigitBit;
}UDigit;
extern volatile StructLCD MediumLCD;
extern volatile UDigit UpdatedDigit;
void LcdInit(void);
void LCD_7SEG(void);
void LCD_Update(void);
#endif /* LCD_DRIVER_H */
编辑:在变量定义之间添加 printf 行意外有效。如果我注释掉这些行,问题仍然存在。这种行为对我来说仍然没有意义。
编辑2:添加完整代码。
void LCD_7SEG(void)
{
unsigned char buffer= 0x11; // assign a value
printf("%d\n", buffer);
UpdatedDigit.DigitChar = buffer; // the value is passed successfully, LCD shows SEG_A and SEGE as expected.
printf("%d\n", UpdatedDigit.DigitChar);
编辑 3:添加 unsigned char 的定义。
<stdint.h>
#ifndef uint8_t
typedef unsigned char uint8_t;
#define uint8_t uint8_t
#define UINT8_MAX (255)
#endif
最佳答案
试试这个:
添加
void LCD_Set(int value)
{
UpdatedDigit.DigitChar = value;
}
修改
void LCD_7SEG(void)
{
LCD_Set(0xff);
}
关于c - 在 C 中将一个变量分配给 union 中的另一个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48077596/
我想做的是让 JTextPane 在 JPanel 中占用尽可能多的空间。对于我使用的 UpdateInfoPanel: public class UpdateInfoPanel extends JP
我在 JPanel 中有一个 JTextArea,我想将其与 JScrollPane 一起使用。我正在使用 GridBagLayout。当我运行它时,框架似乎为 JScrollPane 腾出了空间,但
我想在 xcode 中实现以下功能。 我有一个 View Controller 。在这个 UIViewController 中,我有一个 UITabBar。它们下面是一个 UIView。将 UITab
有谁知道Firebird 2.5有没有类似于SQL中“STUFF”函数的功能? 我有一个包含父用户记录的表,另一个表包含与父相关的子用户记录。我希望能够提取用户拥有的“ROLES”的逗号分隔字符串,而
我想使用 JSON 作为 mirth channel 的输入和输出,例如详细信息保存在数据库中或创建 HL7 消息。 简而言之,输入为 JSON 解析它并输出为任何格式。 最佳答案 var objec
通常我会使用 R 并执行 merge.by,但这个文件似乎太大了,部门中的任何一台计算机都无法处理它! (任何从事遗传学工作的人的附加信息)本质上,插补似乎删除了 snp ID 的 rs 数字,我只剩
我有一个以前可能被问过的问题,但我很难找到正确的描述。我希望有人能帮助我。 在下面的代码中,我设置了varprice,我想添加javascript变量accu_id以通过rails在我的数据库中查找记
我有一个简单的 SVG 文件,在 Firefox 中可以正常查看 - 它的一些包装文本使用 foreignObject 包含一些 HTML - 文本包装在 div 中:
所以我正在为学校编写一个 Ruby 程序,如果某个值是 1 或 3,则将 bool 值更改为 true,如果是 0 或 2,则更改为 false。由于我有 Java 背景,所以我认为这段代码应该有效:
我做了什么: 我在这些账户之间创建了 VPC 对等连接 互联网网关也连接到每个 VPC 还配置了路由表(以允许来自双方的流量) 情况1: 当这两个 VPC 在同一个账户中时,我成功测试了从另一个 La
我有一个名为 contacts 的表: user_id contact_id 10294 10295 10294 10293 10293 10294 102
我正在使用 Magento 中的新模板。为避免重复代码,我想为每个产品预览使用相同的子模板。 特别是我做了这样一个展示: $products = Mage::getModel('catalog/pro
“for”是否总是检查协议(protocol)中定义的每个函数中第一个参数的类型? 编辑(改写): 当协议(protocol)方法只有一个参数时,根据该单个参数的类型(直接或任意)找到实现。当协议(p
我想从我的 PHP 代码中调用 JavaScript 函数。我通过使用以下方法实现了这一点: echo ' drawChart($id); '; 这工作正常,但我想从我的 PHP 代码中获取数据,我使
这个问题已经有答案了: Event binding on dynamically created elements? (23 个回答) 已关闭 5 年前。 我有一个动态表单,我想在其中附加一些其他 h
我正在尝试找到一种解决方案,以在 componentDidMount 中的映射项上使用 setState。 我正在使用 GraphQL连同 Gatsby返回许多 data 项目,但要求在特定的 pat
我在 ScrollView 中有一个 View 。只要用户按住该 View ,我想每 80 毫秒调用一次方法。这是我已经实现的: final Runnable vibrate = new Runnab
我用 jni 开发了一个 android 应用程序。我在 GetStringUTFChars 的 dvmDecodeIndirectRef 中得到了一个 dvmabort。我只中止了一次。 为什么会这
当我到达我的 Activity 时,我调用 FragmentPagerAdapter 来处理我的不同选项卡。在我的一个选项卡中,我想显示一个 RecyclerView,但他从未出现过,有了断点,我看到
当我按下 Activity 中的按钮时,会弹出一个 DialogFragment。在对话框 fragment 中,有一个看起来像普通 ListView 的 RecyclerView。 我想要的行为是当
我是一名优秀的程序员,十分优秀!