Вложений: 1
Re: Осцилограф на ЖКИ, помогите разобраться
Так правильно вроде работает но как предделитель менять для корректного отображения вольтажа
PHP код:
#include <ks0108.h>
byte MyBuff[128];
byte i ;
int V;
int button = 12;
int out1 = 0;
int out2 = 1;
int out3 = 2;
int out4 = 3;
int M = 0;
int L = 0;
#include "Arial14.h"
void setup()
{
pinMode(button, INPUT);
digitalWrite(button, HIGH);
pinMode(out1, INPUT);
pinMode(out2, INPUT);
pinMode(out3, INPUT);
pinMode(out4, INPUT);
GLCD.Init(NON_INVERTED);
GLCD.ClearScreen();
GLCD.SelectFont(Arial_14);
GLCD.GotoXY(7, 2);
GLCD.Puts("Oscilloscop V1.1");
GLCD.DrawRoundRect(4,0,115,18, 5, BLACK);
delay(3000);
}
void loop()
{
for (i=0; i < 128; i++)
{
MyBuff[i] = analogRead(5)/16;
}
M = digitalRead(button);
if(M == 0 ){delay(200);L+1;}
switch(L){
case1:
digitalWrite(out1, LOW);
break;
case2:
digitalWrite(out2, LOW);
break;
case3:
digitalWrite(out3, LOW);
break;}
if(L == 4){ digitalWrite(out4, LOW);L=0;}
GLCD.ClearScreen();
V = analogRead(5)/204;
GLCD.GotoXY(1, 2);
GLCD.SelectFont(Arial_14);
GLCD.PrintNumber(V);
GLCD.DrawLine(1,15,5,15, BLACK);
GLCD.DrawLine(1,25,5,25, BLACK);
GLCD.DrawLine(1,35,5,35, BLACK);
GLCD.DrawLine(1,45,5,45, BLACK);
GLCD.DrawLine(1,55,5,55, BLACK);
GLCD.DrawLine(10,1,10,5, BLACK);
GLCD.DrawLine(25,1,25,5, BLACK);
GLCD.DrawLine(40,1,40,5, BLACK);
GLCD.DrawLine(55,1,55,5, BLACK);
GLCD.DrawLine(70,1,70,5, BLACK);
GLCD.DrawLine(85,1,85,5, BLACK);
GLCD.DrawLine(100,1,100,5, BLACK);
GLCD.DrawLine(115,1,115,5, BLACK);
for (i=0; i < 128; i++)
{
GLCD.DrawLine(i,64-MyBuff[i],i+1,64-MyBuff[i+1],BLACK);
}
}
Re: Осцилограф на ЖКИ, помогите разобраться
Как реализовать отображение вольтажа не 5V а скажем 4,73V т.д отображать с запятой целое и десятичное числа
Re: Осцилограф на ЖКИ, помогите разобраться
Как то так :)
PHP код:
int x;
int y;
float z;
x = 1;
y = x / 2; // y равен 0, тип int не может хранить дробные числа
z = (float)x / 2.0; // z равен 0.5 (следует использовать 2.0, а не 2)
Re: Осцилограф на ЖКИ, помогите разобраться
Вот так с десятичными и сотыми вольта работает спасибо за пример CHIP:eek:
PHP код:
int x;
float z;
float m;
void setup() {
Serial.begin(9600);
}
void loop() {
x = analogRead(0)/3;
z = (float)x / 6.00;
m = (float)z / 12.00;
Serial.println(m);
delay(10);
}
Re: Осцилограф на ЖКИ, помогите разобраться
Но как вывести на дисплей полученные значения не могу понять толи в библиотеке нет такой возможности то-ли я дурак но выводится только целые числа до точки :confused:
PHP код:
#include <ks0108.h>
byte MyBuff[128];
byte i ;
int V;
int x;
float z;
float m;
#include "Arial14.h"
void setup()
{
GLCD.Init(NON_INVERTED);
GLCD.ClearScreen();
GLCD.SelectFont(Arial_14);
GLCD.GotoXY(7, 2);
GLCD.Puts("Oscilloscop V1.1");
GLCD.DrawRoundRect(4,0,115,18, 5, BLACK);
delay(3000);
}
void loop()
{
for (i=0; i < 128; i++)
{
MyBuff[i] = analogRead(5)/16;
}
GLCD.ClearScreen();
x = analogRead(5)/3;
z = (float)x / 6.00;
m = (float)z / 12.00;
GLCD.GotoXY(1, 2);
GLCD.SelectFont(Arial_14);
GLCD.PrintNumber(m);
GLCD.DrawLine(1,15,5,15, BLACK);
GLCD.DrawLine(1,25,5,25, BLACK);
GLCD.DrawLine(1,35,5,35, BLACK);
GLCD.DrawLine(1,45,5,45, BLACK);
GLCD.DrawLine(1,55,5,55, BLACK);
//GLCD.DrawLine(10,1,10,5, BLACK);
GLCD.DrawLine(25,1,25,5, BLACK);
GLCD.DrawLine(40,1,40,5, BLACK);
GLCD.DrawLine(55,1,55,5, BLACK);
GLCD.DrawLine(70,1,70,5, BLACK);
GLCD.DrawLine(85,1,85,5, BLACK);
GLCD.DrawLine(100,1,100,5, BLACK);
GLCD.DrawLine(115,1,115,5, BLACK);
for (i=0; i < 128; i++)
{
GLCD.DrawLine(i,64-MyBuff[i],i+1,64-MyBuff[i+1],BLACK);
}
}
Re: Осцилограф на ЖКИ, помогите разобраться
По крайней мере не нашел в библиотеке что-бы выводить дробные числа
PHP код:
ks0108.h - Arduino library support for ks0108 and compatable graphic LCDs
Copyright (c)2008 Michael Margolis All right reserved
mailto:memargolis@hotmail.com?subject=KS0108_Library
The high level functions of this library are based on version 1.1 of ks0108 graphics routines
written and copyright by Fabian Maximilian Thiele. His sitelink is dead but
you can obtain a copy of his original work here:
http://www.scienceprog.com/wp-content/uploads/2007/07/glcd_ks0108.zip
Code changes include conversion to an Arduino C++ library, rewriting the low level routines
to read busy status flag and support a wider range of displays, adding more flexibility
in port addressing and improvements in I/O speed. The interface has been made more Arduino friendly
and some convenience functions added.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Version: 1.0 - May 8 2008 - initial release
Version: 1.0a - Sep 1 2008 - simplified command pin defines
Version: 1.0b - Sep 18 2008 - replaced <wiring.h> with boolean typedef for rel 0012
Version: 1.1 - Nov 7 2008 - restructured low level code to adapt to panel speed
- moved chip and panel configuration into seperate header files
- added fixed width system font
Version: 2 - May 26 2009 - second release
- added support for Mega and Sanguino, improved panel speed tolerance, added bitmap support
*/
#include <inttypes.h>
typedef uint8_t boolean;
typedef uint8_t byte;
#include <avr/pgmspace.h>
#ifndef KS0108_H
#define KS0108_H
#define GLCD_VERSION 2 // software version of this library
// Chip specific includes
#if defined(__AVR_ATmega1280__)
#include "ks0108_Mega.h" // include this for the Arduino Mega other ATmega1280 boards
#elif defined (__AVR_ATmega644__) // TODO - check this define
#include "ks0108_Sanguino.h" // include this for Sanguino or ATmega644 boards
#else
#include "ks0108_Arduino.h" // include this for the Arduino or other ATmega168 boards
#endif
#include "ks0108_Panel.h" // this contains LCD panel specific configuration
// macros for pasting port defines
#define GLUE(a, b) a##b
#define PORT(x) GLUE(PORT, x)
#define PIN(x) GLUE(PIN, x)
#define DDR(x) GLUE(DDR, x)
// paste together the port definitions if using nibbles
#define LCD_DATA_IN_LOW PIN(LCD_DATA_LOW_NBL) // Data I/O Register, low nibble
#define LCD_DATA_OUT_LOW PORT(LCD_DATA_LOW_NBL) // Data Output Register - low nibble
#define LCD_DATA_DIR_LOW DDR(LCD_DATA_LOW_NBL) // Data Direction Register for Data Port, low nibble
#define LCD_DATA_IN_HIGH PIN(LCD_DATA_HIGH_NBL) // Data Input Register high nibble
#define LCD_DATA_OUT_HIGH PORT(LCD_DATA_HIGH_NBL) // Data Output Register - high nibble
#define LCD_DATA_DIR_HIGH DDR(LCD_DATA_HIGH_NBL) // Data Direction Register for Data Port, high nibble
#define lcdDataOut(_val_) LCD_DATA_OUT(_val_)
#define lcdDataDir(_val_) LCD_DATA_DIR(_val_)
// macros to handle data output
#ifdef LCD_DATA_NIBBLES // data is split over two ports
#define LCD_DATA_OUT(_val_) \
LCD_DATA_OUT_LOW = (LCD_DATA_OUT_LOW & 0xF0)| (_val_ & 0x0F); LCD_DATA_OUT_HIGH = (LCD_DATA_OUT_HIGH & 0x0F)| (_val_ & 0xF0);
#define LCD_DATA_DIR(_val_)\
LCD_DATA_DIR_LOW = (LCD_DATA_DIR_LOW & 0xF0)| (_val_ & 0x0F); LCD_DATA_DIR_HIGH = (LCD_DATA_DIR_HIGH & 0x0F)| (_val_ & 0xF0);
#else // all data on same port (low equals high)
#define LCD_DATA_OUT(_val_) LCD_DATA_OUT_LOW = (_val_);
#define LCD_DATA_DIR(_val_) LCD_DATA_DIR_LOW = (_val_);
#endif
// Commands
#ifdef HD44102
#define LCD_ON 0x39
#define LCD_OFF 0x38
#define LCD_DISP_START 0x3E // Display start page 0
#else
#define LCD_ON 0x3F
#define LCD_OFF 0x3E
#define LCD_DISP_START 0xC0
#endif
#define LCD_SET_ADD 0x40
#define LCD_SET_PAGE 0xB8
#define LCD_BUSY_FLAG 0x80
// Colors
#define BLACK 0xFF
#define WHITE 0x00
// useful user contants
#define NON_INVERTED false
#define INVERTED true
// Font Indices
#define FONT_LENGTH 0
#define FONT_FIXED_WIDTH 2
#define FONT_HEIGHT 3
#define FONT_FIRST_CHAR 4
#define FONT_CHAR_COUNT 5
#define FONT_WIDTH_TABLE 6
// Uncomment for slow drawing
// #define DEBUG
typedef struct {
uint8_t x;
uint8_t y;
uint8_t page;
} lcdCoord;
typedef uint8_t (*FontCallback)(const uint8_t*);
uint8_t ReadPgmData(const uint8_t* ptr); //Standard Read Callback
#define DrawVertLine(x, y, length, color) FillRect(x, y, 0, length, color)
#define DrawHoriLine(x, y, length, color) FillRect(x, y, length, 0, color)
#define DrawCircle(xCenter, yCenter, radius, color) DrawRoundRect(xCenter-radius, yCenter-radius, 2*radius, 2*radius, radius, color)
#define ClearScreenX() FillRect(0, 0, (DISPLAY_WIDTH-1), (DISPLAY_HEIGHT-1), WHITE)
#define ClearSysTextLine(_line) FillRect(0, (line*8), (DISPLAY_WIDTH-1), ((line*8)+ 7), WHITE )
class ks0108 // shell class for ks0108 glcd code
{
private:
lcdCoord Coord;
boolean Inverted;
FontCallback FontRead;
uint8_t FontColor;
const uint8_t* Font;
uint8_t ReadData(void);
uint8_t DoReadData(uint8_t first);
void WriteCommand(uint8_t cmd, uint8_t chip);
void WriteData(uint8_t data); // experts can make this public but the functionality is not documented
inline void Enable(void);
inline void SelectChip(uint8_t chip);
void WaitReady( uint8_t chip);
public:
ks0108();
// Control functions
void Init(boolean invert);
void GotoXY(uint8_t x, uint8_t y);
// Graphic Functions
void ClearPage(uint8_t page, uint8_t color);
void ClearScreen(uint8_t color = WHITE);
void DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
void DrawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color);
void DrawRoundRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t radius, uint8_t color);
void FillRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color);
void InvertRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height);
void SetInverted(boolean invert);
void SetDot(uint8_t x, uint8_t y, uint8_t color);
void DrawBitmap(const uint8_t * bitmap, uint8_t x, uint8_t y, uint8_t color);
// Font Functions
void SelectFont(const uint8_t* font, uint8_t color=BLACK, FontCallback callback=ReadPgmData); // defualt arguments added, callback now last arg
int PutChar(char c);
void Puts(char* str);
void Puts_P(PGM_P str);
void PrintNumber(long n);
void CursorTo( uint8_t x, uint8_t y); // 0 based coordinates for fixed width fonts (i.e. systemFont5x7)
uint8_t CharWidth(char c);
uint16_t StringWidth(char* str);
uint16_t StringWidth_P(PGM_P str);
};
extern ks0108 GLCD;
#endif
Re: Осцилограф на ЖКИ, помогите разобраться
Сначала нужно вычислить целую часть потом дробную и разместить в две разные переменные
Re: Осцилограф на ЖКИ, помогите разобраться
доработал код теперь корректно отображается Вольтаж Добавил менюшку Датчик температуры думаю еще прикрутить к осциллографу внешний переключающийся делитель на сдвиговом регистре и программно менять предделитель на 5-20-200 и 1000 вольт пока только в планах думаю как реализовать нужно ведь еще и отображать на дисплее Инфу о том какой включен делитель и защиту какую нибудь на вход поставить хоть варистор что ли пока не придумал
PHP код:
#include <ks0108.h>
#include <OneWire.h>
byte MyBuff[128];
byte i ;
int V;
int button = 2;
int Lite = 3;
int B;
int Lm = 0;
int Ls = 0;
OneWire ds(12);
#include "Arial14.h"
//------------------------------------------------------------------
void setup()
{
pinMode(1,INPUT);
pinMode(button,INPUT);
pinMode(Lite, OUTPUT);
digitalWrite(button, HIGH);
digitalWrite(1, HIGH);
GLCD.Init(NON_INVERTED);
GLCD.ClearScreen();
GLCD.SelectFont(Arial_14);
GLCD.GotoXY(7, 2);
GLCD.Puts("Oscilloscop V1.2");
GLCD.DrawRoundRect(4,0,115,18, 5, BLACK);
delay(3000);
GLCD.ClearScreen();
}
//------------------------------------------------------------------
void menu(){
B = digitalRead(button);
if(B == 0){Ls = digitalRead(1);if(Ls == 0){GLCD.GotoXY(2, 4);
GLCD.SelectFont(Arial_14);
GLCD.Puts("OFF");
delay(2000);
GLCD.ClearScreen();
digitalWrite(Lite, LOW);}}
if(B == 0){GLCD.ClearScreen();
delay(500); Lm++; }
else{
switch(Lm){
//---------------------------------------------
case 0:
GLCD.GotoXY(2, 4);
GLCD.SelectFont(Arial_14);
GLCD.Puts("Menu:");
break;
//---------------------------------------------
case 1:
GLCD.GotoXY(2, 4);GLCD.Puts("Menu:");
GLCD.GotoXY(2, 16);
GLCD.SelectFont(Arial_14);
GLCD.Puts("Lite");
Ls = digitalRead(1);
if(Ls == 0){digitalWrite(Lite, HIGH);GLCD.ClearScreen();
GLCD.GotoXY(2, 16);
GLCD.SelectFont(Arial_14);
GLCD.Puts("Lite ON");
delay(1000);}
Ls = digitalRead(1);
if(Ls == 0){GLCD.ClearScreen();
GLCD.GotoXY(2, 4);GLCD.Puts("Menu:");
GLCD.GotoXY(2, 16);
GLCD.SelectFont(Arial_14);
GLCD.Puts("Lite OFF");digitalWrite(Lite, LOW);delay(1000);}
break;
//---------------------------------------------
case 2:
GLCD.GotoXY(2, 4);GLCD.Puts("Menu:");
GLCD.GotoXY(2, 16);
GLCD.SelectFont(Arial_14);
GLCD.Puts("Oscilloscop");
Ls = digitalRead(1);
if(Ls == 0){delay(500);
oscilloscop();}
break;
//---------------------------------------------
//---------------------------------------------
case 4:
delay(100); Lm = 0;
GLCD.ClearScreen();
break;}}
if(Lm == 3){GLCD.ClearScreen();
GLCD.GotoXY(2, 4);GLCD.Puts("Menu:");
GLCD.GotoXY(2, 16);
GLCD.SelectFont(Arial_14);
GLCD.Puts("Temp:");
byte i;
byte present = 0;
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
ds.reset_search();
return;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
GLCD.Puts("Not Connect!");
return;
}
if ( addr[0] != 0x28) {
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // запускаем конвертацию
delay(10); // скорее всего достаточно 750ms
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // считываем ОЗУ датчика
for ( i = 0; i < 9; i++) { // обрабатываем 9 байт
data[i] = ds.read();
}
// высчитываем температуру :)
int HighByte, LowByte, TReading, Tc_100;
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
Tc_100 = TReading/2;
GLCD.PrintNumber(Tc_100/10);
GLCD.Puts(".");
int Celoe;
float Des;
int Drob;
Drob = Tc_100/10;
Des = Tc_100/10.0;
Celoe = (Des-Drob)*10;
GLCD.PrintNumber(Celoe);
delay(1000);}
}
//------------------------------------------------------------------
void oscilloscop(){
for (i=0; i < 128; i++)
{
MyBuff[i] = analogRead(5)/16;
}
//GLCD.ClearScreen();
GLCD.FillRect(0,0,128,64, WHITE);
int x;
float z;
int L;
x = analogRead(5)/20;
z = analogRead(5)/20.0;
L = (z-x)*10;
GLCD.GotoXY(1, 2);
GLCD.SelectFont(Arial_14);
GLCD.PrintNumber(x/10);
GLCD.Puts(".");
GLCD.PrintNumber(L);
GLCD.DrawLine(1,15,5,15, BLACK);
GLCD.DrawLine(1,25,5,25, BLACK);
GLCD.DrawLine(1,35,5,35, BLACK);
GLCD.DrawLine(1,45,5,45, BLACK);
GLCD.DrawLine(1,55,5,55, BLACK);
//GLCD.DrawLine(10,1,10,5, BLACK);
GLCD.DrawLine(25,1,25,5, BLACK);
GLCD.DrawLine(40,1,40,5, BLACK);
GLCD.DrawLine(55,1,55,5, BLACK);
GLCD.DrawLine(70,1,70,5, BLACK);
GLCD.DrawLine(85,1,85,5, BLACK);
GLCD.DrawLine(100,1,100,5, BLACK);
GLCD.DrawLine(115,1,115,5, BLACK);
for (i=0; i < 128; i++)
{
GLCD.DrawLine(i,64-MyBuff[i],i+1,64-MyBuff[i+1],BLACK);
}
B = digitalRead(button);
if(B == 0){delay(1000);}
Ls = digitalRead(1);
if(Ls == 0){GLCD.ClearScreen();delay(1000);loop();}
else{oscilloscop();}
}
//------------------------------------------------------------------
void loop()
{
menu();
}
//------------------------------------------------------------------
Re: Осцилограф на ЖКИ, помогите разобраться
Защиту можно на стабилитроне сделать
А видео когда можно посмотреть будет?
Re: Осцилограф на ЖКИ, помогите разобраться
Цитата:
Сообщение от
Chip
Защиту можно на стабилитроне сделать
А видео когда можно посмотреть будет?
А что отснять ? что интересует? Скоро фотки выложу и схему сборки :)
Re: Осцилограф на ЖКИ, помогите разобраться