Monday, September 21, 2009

simple oscilloscope using Z8F0823 and N3310 LCD

Do-it-yourself simple oscilloscope using Zilog Z8F0823 and Nokia 3310 LCD.

diagram:
demo:


sample "main.c" source code:
 #include <ez8.h>  
#include "delay.c"
#include "lcd3310.c"
void erase_column(char x);
void lcd_pixel (char x, char y);
void lcd_vertical_line (char x, char y1, char y2);
void main()
{
char x, y1, y2, samples[84];
//setup ADC
PBDD |= 0x01; // PB0 input direection
PBAF |= 0x01; // PB0 Alernate function on
PBAFS1 |= 0x01; // PB0 analog input
ADCCTL1 |= 0x80; // 2V Vref
ADCCTL0 |= 0x10; // Set ADC Control Register; continuous
//initialize 3310 LCD
lcd_init();
lcd_clear();
//display sample alphanumerics
lcd_gotoxy(0,1);
lcd_puts("DIY scope");
lcd_gotoxy(0,2);
lcd_puts("Zilog Z8F0823");
lcd_gotoxy(0,3);
lcd_puts("Nokia 3310 LCD");
lcd_gotoxy(0,5);
lcd_puts("yus - elab.ph");
delay_ms(3000);
while(1)
{
//store samples
for(x=0; x<=84; x++)
{
samples[x] = ADHR; //read ADC value (high byte)
delay_us(100); //adjust this delay to vary the sampling frequency
}
//plot samples
erase_column(0);
for(x=0; x<=84; x++)
{
erase_column(x+1);
y1 = samples[x] / 2.5; //scale to {0..47} range
y1 = 47 - y1; //invert position (optional)
y2 = samples[x+1] / 2.5; //scale to {0..47} range
y2 = 47 - y2; //invert position (optional)
//lcd_pixel(x,y1);
lcd_vertical_line(x,y1,y2); //plot
}
delay_ms(50);
}
}
void erase_column(char x)
{
char line;
if(x>83) return;
for(line=0; line<6; line++)
{
lcd_gotoxy(x, line);
lcd_send(0x00, LCD_TDATA);
}
}
void lcd_pixel (char x, char y)
{
char data;
if ((x > 83) || (y > 47)) return;
data = 0x01<<(y%8);
lcd_gotoxy(x, (y>>3));
lcd_send(data, LCD_TDATA);
}
void lcd_vertical_line (char x, char y1, char y2)
{
char i, temp, line1, line2, data;
if( (x>83) || (y1>47) || (y2>47) ) return; //exit if out of range
if(y1>y2)
{
temp = y1;
y1 = y2; //swap variables
y2 = temp;
}
line1 = y1>>3; //divide by 8
line2 = y2>>3;
for(i=line1; i<=line2; i++)
{
data = 0xff;
lcd_gotoxy(x,i);
if(i==line1)
{
data = 0;
temp = 8 - (y1 % 8);
while(temp--) data |= (0x80>>temp);
}
if(i==line2)
{
temp = 7 - (y2 % 8);
while(temp--) data &= ~(0x80>>temp);
}
lcd_send(data, LCD_TDATA);
}
}

complete code and diagram here: N3310 LCD Oscilloscope using Z8F0823.rar

1 comment:

  1. Hello Yus... is a sustrator OPAMP configuration?...which is the purpose of putting that setup?

    ReplyDelete