- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我这里有一个新问题。我仍在为 PIC(xc8 编译器)学习 C,作为一个初学者项目,我正在用流行的 ds18b20 和我身边的 pic16f628 做一个温度计。我的程序在允许运行时表现良好,但当我使用指针、结构、数组等在函数中返回多个值时,我注意到有些东西出了问题,现在 PC 来回运行不允许程序按顺序运行,至少这是我在 mplabx 中使用模拟器时所看到的。我很确定我忘记了一些关于程序和/或内存位置的东西,但我不知道是什么或为什么。有人能帮我吗?我把主要代码贴在这里,你还需要什么?
/*
* File: termometro.c
* Author: zakkos
* Created on April 18, 2013, 2:20 PM
*
* /
/*ESSENTIAL DEFINITIONS*/
#define _XTAL_FREQ 4000000
/*INCLUSIONS*/
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <lcd.h>
#include <1-wire.h>
/*CONFIG PRAGMA*/
#pragma config BOREN = OFF, CPD = OFF, FOSC = INTOSCIO, MCLRE = OFF, WDTE = OFF, CP = OFF, LVP = OFF, PWRTE = ON
//typedef unsigned char uint8_t;
void read_temp(void);
union {
char eratura;
char decimali;
}temps;
int main(void) {
INTCON = 0x00;
PIE1 = 0x00;
CMCON = 0x07; //disabilito i comparatori - disable comparators
TRISA = 0x00;
PORTA = 0x00;
TRISB = 0x00;
PORTB = 0x00;
const char decims[16] = {0, 0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9};
char temp;
lcd_init();
lcd_send_cmd(LCD_CLR);
lcd_send_cmd(LCD_HOME);
writeString("Hello,");
lcd_send_cmd(LCD_LN2);
writeString("World!");
__delay_ms(1000);
while(1)
{
read_temp();
lcd_send_cmd(LCD_CLR);
lcd_send_cmd(LCD_HOME);
writeString("Temp:");
lcd_send_cmd(LCD_LN2);
if((temps.eratura & 0x80)){ //if sign bit is set
temps.eratura = ~temps.eratura; //2's complement
temps.eratura += 1;
temps.decimali = ~temps.decimali; //2's complement
temps.decimali += 1;
lcd_send_dat(0x2D); //minus
}
temp = (temps.eratura/100)& 0x0F; //centinaia 157/100=1 (hundreds)
if(temp){
lcd_send_dat(0x30 | temp);
temp = ((temps.eratura/10)%10) & 0x0F; //decine 157/10=15%10=5 (tens if hundreds is set, meaning it will display also a 0)
lcd_send_dat(0x30 | temp);
} else {
temp = ((temps.eratura/10)%10) & 0x0F; //decine 157/10=15%10=5 (tens if hundreds is no set, meaning it will not display if 0)
if(temp){lcd_send_dat(0x30 | temp);
}
}
lcd_send_dat(0x30 | (temps.eratura%10)& 0x0F); //unita 157%10=7 (ones)
lcd_send_dat(0x2E); //dot
lcd_send_dat(0x30 | decims[temps.decimali] & 0x0F); //decimals
lcd_send_dat(0xDF); //degrees
}
}
void read_temp(void){
char scratchpad[9];
while(ow_reset());
ow_write_byte(0xCC);
ow_write_byte(0x44);
while(ow_read_bit()==0);
__delay_ms(1);
while(ow_reset());
ow_write_byte(0xCC);
ow_write_byte(0xBE);
for(char k=0;k<10;k++){
scratchpad[k] = ow_read_byte();
}
temps.decimali = scratchpad[0] & 0x0F;
temps.eratura = (scratchpad[1] << 4)|(scratchpad[0] >> 4);
return;
}
最佳答案
for(char k=0;k<10;k++){
scratchpad[k] = ow_read_byte();
}
...将从 0-9(10 个字符)运行,而...
char scratchpad[9];
...只为9保留空间。这可能会覆盖堆栈(即返回地址)
关于C for 16f628,程序计数器失控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16308609/
我正在尝试根据空白(空格、返回键、制表符)解析字符串(有些可能很长、段落)。当前使用String.split("\\s++")。在我们更新的上一个项目中,我们只是使用了StringTokenizer。
我在过去可以工作的 Oracle 10 SQL 中有一个分层查询。但是,我删除了它所基于的物化 View ,现在我无法让它正确显示,甚至完全离开了那个 View 。 原始查询如下所示: select
下面的代码有效。该代码调用 API 来获取历史交易(每次拉取 100 笔交易)。因为存在限制 - 允许调用 API 的次数和频率 - 结构类似于递归。 流程如下: 获取当前的 MAX tradeId
.inDB { background-color: #53354A; color: #53354A; padding: 2% 3%; height: 100px; width: 1
echo ''.$result['title'].' '.$result['description'].''; 为什么 .post
我正在使用 Gzip 压缩和 Zlib 压缩来加速我的网站 我使用了下面的代码 ob_start("ob_gzhandler");在包含在所有页面上的公共(public)文件中, lib.output
我是一名优秀的程序员,十分优秀!