G2KHH

        Küsimus Armeenia raadiole:
          Millised sarnasused on võimul ja jalgrattal?
        Vastus:
          Rool tipus, kett allosas.

        http://www.anekdot.ru/tags/армянское радио

Joonistab aeda (raami). Vajutades ekraaninupudele

  [0]    [1]    [2]    [3]
  L(eft) d(own) U(p)   r(ight)*

uss liigub. Tõmbab ennast kokku kui liikumist pole. Avastab suvalist musta pikslit enda teel (aed või enda keha) vaata "impact".

*) Järjekord nagu vi redaktoris "hjkl".

------------------------------------------------------------------------

presnak2.prj

; ************************************************************
; PROJECT:
; AUTHOR:
; ************************************************************
; Micro + software running
; ------------------------------------------------------------
.MICRO "ATmega8"
.TOOLCHAIN "GCC" ; Bug: use rebuild with errors; then build
.GCCPATH   "C:\WinAVR"
.GCCMAKE   AUTO
.TARGET    "presnak2.hex"
.SOURCE    "presnak2.c"

.TRACE              ; Activate micro trace

; Following lines are optional; if not included
; exactly these values are taken by default
; ------------------------------------------------------------
.POWER VDD=5 VSS=0  ; Power nodes
.CLOCK 1meg         ; Micro clock
.STORE 250m         ; Trace (micro+signals) storage time

; Micro nodes: RESET, AREF, PB0-PB7, PC0-PC6, PD0-PD7, ACO,
;              TIM1OVF, ADC6, ADC7
; Define here the hardware around the micro

;                 RS  RW  E   |<---        data         --->| CS1 CS2 /RST LED+ LED-
Xglcd _graphiclcd PC0 PC1 PC2 PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0 PC4 PC3 VDD  VDD  VSS

K0 VSS PB0
K1 VSS PB1
K2 VSS PB2
K3 VSS PB3

--------------------

#include <math.h>
#include <avr/io.h>
#include <util/delay.h>

// GLCD module connections
#define GLCD_Data   PORTD
#define GLCD_DataIn PIND
#define GLCD_Dir    DDRD

#define GLCD_RS  PC0
#define GLCD_RW  PC1
#define GLCD_EN  PC2
#define GLCD_CS2 PC3
#define GLCD_CS1 PC4
// End GLCD module connections

#define  PORT_ON(port,pin) (port|=(1<<pin))
#define  PORT_OFF(port,pin) (port&=~(1<<pin))

void GLCD_Init( void);
void Enable_Pulse(void);
void GLCD_ON(void);
void GOTO_COL(unsigned int);
void GOTO_ROW(unsigned int);
void GOTO_XY(unsigned int, unsigned int);
void GLCD_Write(unsigned short);
unsigned short GLCD_Read(unsigned short);
unsigned short Read_Point(unsigned short, unsigned short);
void GLCD_Clrln(unsigned short);
void GLCD_CLR(void);
void Draw_Point(unsigned short, unsigned short, unsigned short);

void draw_garden( void);
void draw_impact( unsigned short, unsigned short);
void GLCD_Init( void);

void Enable_Pulse()
{
    PORT_ON(PORTC,GLCD_EN); // EN high
    _delay_us(5);
    PORT_OFF( PORTC, GLCD_EN); // EN low
    _delay_us(5);
}

void GLCD_ON()
{
    //Activate both chips
    PORT_OFF( PORTC, GLCD_CS1);
    PORT_OFF( PORTC, GLCD_CS2);
    PORT_OFF( PORTC, GLCD_RS); //RS low --> command
    PORT_OFF( PORTC, GLCD_RW); //RW low --> write
    GLCD_Data = 0x3F;          //ON command
    Enable_Pulse();
}

void GOTO_COL(unsigned int x)
{
    unsigned short Col_Data;
    PORT_OFF( PORTC, GLCD_RS);      //RS low --> command
    PORT_OFF( PORTC, GLCD_RW);      //RW low --> write
    if(x<64)                        //left section
    {
        PORT_OFF( PORTC, GLCD_CS1); //select chip 1
        PORT_ON( PORTC, GLCD_CS2);  //deselect chip 2
        Col_Data = x;               //put column address on data port
    }
    else                            //right section
    {
        PORT_OFF( PORTC, GLCD_CS2);
        PORT_ON( PORTC, GLCD_CS1);
        Col_Data = x-64;            //put column address on data port
    }
    Col_Data = (Col_Data | 0x40 ) & 0x7F;  //Command format
    GLCD_Data = Col_Data;
    Enable_Pulse();
}

void GOTO_ROW(unsigned int y)
{
    unsigned short Col_Data;
    PORT_OFF( PORTC, GLCD_RS);     //RS low --> command
    PORT_OFF( PORTC, GLCD_RW);     //RW low --> write
    Col_Data = (y | 0xB8 ) & 0xBF; //put row address on data port set command
    GLCD_Data = Col_Data;
    Enable_Pulse();
}

void GOTO_XY(unsigned int x,unsigned int y)
{
    GOTO_COL(x);
    GOTO_ROW(y);
}

void GLCD_Write(unsigned short b)
{
    PORT_ON( PORTC, GLCD_RS);          //RS high --> data
    PORT_OFF( PORTC, GLCD_RW);         //RW low --> write
    GLCD_Data = b;                     //put data on data port
    _delay_us(1);
    Enable_Pulse();
}

unsigned short GLCD_Read(unsigned short column)
{
    unsigned short read_data = 0; //Read data here
    GLCD_Dir = 0x00;              //PORTD as Input
    PORT_ON( PORTC, GLCD_RW);     //Read 1
    PORT_ON( PORTC, GLCD_RS);     //Data 1
    if (column>63) {
        PORT_ON( PORTC, GLCD_CS1);
        PORT_OFF( PORTC, GLCD_CS2);
    }
    else {                        //Disable/Enable CS2
        PORT_OFF( PORTC, GLCD_CS1);
        PORT_ON( PORTC, GLCD_CS2);
    }
    _delay_us(5);                 //tasu
    PORT_ON( PORTC, GLCD_EN);     //Latch RAM data into ouput register 1
    _delay_us(1);                 //twl + tf

    //Dummy read
    PORT_OFF( PORTC, GLCD_EN);    //Low Enable 0
    _delay_us(5);
    PORT_ON( PORTC, GLCD_EN);     //latch data from output register to data bus 1
    _delay_us(1);                 //tr + td(twh)

    read_data = GLCD_DataIn;      //Input data
    PORT_OFF( PORTC, GLCD_EN);    //Low Enable to remove data from the bus 0
    _delay_us(1);                 //tdhr
    GLCD_Dir = 0xFF;              //Output again

    return read_data;
}

unsigned short Read_Point(unsigned short x, unsigned short y) {
    GOTO_XY(x,(y/8));
    if ((1<<(y%8)) & GLCD_Read(x)) return 1; else return 0;
}

void GLCD_Clrln(unsigned short ln)
{
    int i;
    GOTO_XY(0,ln);              //At start of line of left side
    GOTO_XY(64,ln);             //At start of line of right side (Problem)
    PORT_OFF( PORTC, GLCD_CS1); //0;
    for( i=0; i<65; i++)
        GLCD_Write(0);
}

void GLCD_CLR()
{
    unsigned short m;
    for( m=0; m<8; m++)
        GLCD_Clrln(m);
}

void Draw_Point(unsigned short x, unsigned short y, unsigned short color)
{
    unsigned short Col_Data;
    GOTO_XY(x,(y/8));
    switch (color)
    {
        case 0: // Light spot
            Col_Data = ~(1<<(y%8)) & GLCD_Read(x);
            break;
        case 1: // Dark spot
            Col_Data = (1<<(y%8)) | GLCD_Read(x);
            break;
    }
    GOTO_XY(x,(y/8));
    GLCD_Write(Col_Data);
}

void GLCD_Init( void) {
    DDRB=0x00;
    PORTB=0xff;
    UCSRB=0x00;

    GLCD_Dir = 0xFF;            // Output on Data Bus
    DDRC = 0xFF;                // Output on Control Bus + Address Bus
    PORT_ON( PORTC, GLCD_CS1);  // De-Activate both chips 1
    PORT_ON( PORTC, GLCD_CS2);
    GLCD_ON();
    GLCD_CLR();
}

void draw_garden( void) {
    unsigned char x = 0;
    unsigned char y = 0;

    for( x = 0; x <= 127; x++) Draw_Point(x, 0, 1);
    for( y = 1; y <= 63; y++) Draw_Point(127, y, 1);
    for( x = 126; x >= 1; x--) Draw_Point(x, 63, 1);
    for( y = 62; y >= 1; y--) Draw_Point(0, y, 1);
}

void draw_impact( unsigned short au, unsigned short av) {
    double fi;
    unsigned short u;
    unsigned short v;
    for(fi=0.05; fi<=1.; fi+=.05) {
        u = au + 3 * sin( 2 * 3.14 * fi);
        v = av + 3 * cos( 2 * 3.14 * fi);
        if (u > 0 && u < 127 && v > 0 && v < 63)
            Draw_Point( u, v, 1);
   }
}

int main ( void) {
    unsigned char c = 0;
    unsigned char u = 63, uold = u;
    unsigned char v = 31, vold = v;

    GLCD_Init();
    draw_garden();
    Draw_Point(u, v, 1);

    while (1) {
        if (bit_is_clear(PINB, 0)) c = 9;
        if (bit_is_clear(PINB, 1)) c = 6;
        if (bit_is_clear(PINB, 2)) c = 12;
        if (bit_is_clear(PINB, 3)) c = 3;
        if (c) {
            uold = u; vold = v;
            switch (c) {
                case 9: u--; break;
                case 6: v++; break;
                case 12: v--; break;
                case 3: u++; break;
            };
            if (Read_Point( u, v)) break;
            Draw_Point(u, v, 1);
            Draw_Point(uold, vold, 0);
        }
        c = 0;
    }
    draw_impact(u, v);
    return 0;
}

------------------------------------------------------------------------

G2IAS

    Minu Ubuntu mingil põhjusel ei taha ennast uuendada Windows 10-ni.
    Mida ma teen valesti ??
    http://www.3dnews.ru/928194

Test 7-Seg indikaatoriga. Vajutades ekraaninupudele

  [0] [1] [2] [3]

näitab

  W(est) S(outh) n(orth) E(ast)
  L(eft) d(own)  U(p)    r(ight)*

nupp

  [5] kustutab taas kõik segmendid (algseis)

*) Järjekord nagu vi redaktoris "hjkl".

------------------------------------------------------------------------

presnake.prj

; ************************************************************
; PROJECT:
; AUTHOR:
; ************************************************************
; Micro + software running
; ------------------------------------------------------------
.MICRO "ATmega8"
.TOOLCHAIN "GCC" ; Bug: use rebuild with errors; then build
.GCCPATH   "C:\WinAVR"
.GCCMAKE   AUTO
.TARGET    "presnake.hex"
.SOURCE    "presnake.c"

.TRACE              ; Activate micro trace

; Following lines are optional; if not included
; exactly these values are taken by default
; ------------------------------------------------------------
.POWER VDD=5 VSS=0  ; Power nodes
.CLOCK 1meg         ; Micro clock
.STORE 250m         ; Trace (micro+signals) storage time

; Micro nodes: RESET, AREF, PB0-PB7, PC0-PC6, PD0-PD7, ACO,
;              TIM1OVF, ADC6, ADC7
; Define here the hardware around the micro

; 8 - digit LED 7 segment display
;
;           0   -   -   -   -   -   -   -
;          | | | 1 | | | | | | 5 | | | | |
;           -   -   -   -   -   -   6   -
;          | | | | | 2 | | 4 | | | | | | |
;           -.  -.  -.  3.  -.  -.  -.  -7

X1 _led7cc PD0 PD1 PD2 PD3 PD4 PD5 PD6 PD7 GND

K0 VSS PB0
K1 VSS PB1
K2 VSS PB2
K3 VSS PB3
K4 VSS PB4

-------------

presnake.c

#include <avr/io.h>
#include <util/delay.h>

/*
  0        -        0        0        -        0        0        0
 5 1      | 1      | 1      | 1      5 1      5 |      5 |      | 1
  -        -        6        6        6        6        6        -
 4 2      | 2      4 |      | 2      | 2      | 2      3 2      | 2
  3.       -.       3.       3.       -.       3.       3.       -.

 00111111 00000110 01011011 01001111 01100110 01101101 01111101 00000111
 0x3f     0x06     0x5b     0x4f     0x66     0x6d     0x7d     0x07

  0        0        0        -        -        -        0        0
 5 1      5 1      5 1      5 |      | |      | 1      5 |      5 |
  6        6        6        6        6        6        6        6
 4 2      | 2      4 2      4 2      4 |      4 2      4 |      4 |
  3.       3.       -.       3.       3.       3.       3.       -.

 01111111 01101111 01110111 01111100 01011000 01011110 01111001 01110001
 0x7f     0x6f     0x77     0x7c     0x58     0x5e     0x79     0x71

  0        -        0        0        -        -        -        -
 5 |      5 |      | |      | |      5 1      5 |      5 1      | |
  -        6        -        -        6        -        -        6
 4 2      4 2      4 |      | 2      4 2      4 |      4 2      4 2
  3.       -.       3.       3.       _.       3.       -.       -.

 00111101 01110100 00011001 00001101 01110110 00111000 00110110 01010100
 0x3d     0x74     0x19     0x0d     0x76     0x38     0x36     0x54

  -        0        0        -        -        -        -        -
 | |      5 1      5 1      | |      5 |      5 |      5 1      | |
  6        6        6        6        6        6        -        -
 4 2      4 |      | 2      4 |      | 2      4 |      4 2      4 2
  3.       -.       -.       -.       3.       3.       3.       3.

 01011100 01110011 01100111 01010000 01101100 01111000 00111110 00011100
 0x5c     0x73     0x67     0x50     0x6c     0x78     0x3e     0x1c

  -        -        -        0        -        -        -        -
 5 1      | |      5 1      | |      | |      | |      | |      | |
  6        -        6        6        -        -        6        6
 4 2      4 2      | 2      | |      | |      | |      | |      | |
  3.       -.       3.       3.       -.       3.       -.       3.

 01111110 00010100 01101110 01001001 00000000 00001000 01000000 01001000
 0x7e     0x14     0x6e     0x49     0x00     0x08     0x40     0x48
*/

unsigned char font[] = {
    0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
    0x7f, 0x6f, 0x77, 0x7c, 0x58, 0x5e, 0x79, 0x71,
    0x3d, 0x74, 0x19, 0x0d, 0x76, 0x38, 0x36, 0x54,
    0x5c, 0x73, 0x67, 0x50, 0x6c, 0x78, 0x3e, 0x1c,
    0x7e, 0x14, 0x6e, 0x49, 0x00, 0x08, 0x40, 0x48
};

void init( void) {
    DDRD=0xff;
    PORTD=0xff;
    DDRB=0x00;
    PORTB=0xff;
    UCSRB=0x00;
}

int main ( void) {
    unsigned char x = 36;
    init();

    while (1) {
        if (bit_is_clear(PINB, 0)) x = 21; // x = 32;
        if (bit_is_clear(PINB, 1)) x = 13; // x = 28;
        if (bit_is_clear(PINB, 2)) x = 30; // x = 23;
        if (bit_is_clear(PINB, 3)) x = 27; // x = 14;
        if (bit_is_clear(PINB, 4)) x = 36;
        PORTD = PORTD = font[ x];
    }
    return 0;
}

========================================================================

G29Ie

                      Люблю мануалы: захочешь выяснить,
                      какой стороной класть негатив в сканер,
                      лезешь в помощь, а там написано:
                      "Положите правильной стороной".

                      Источник: http://fishki.net/anekdot/

Графический дисплей KS0108 -- драйвер и тест для ATMega8, VMLab + WinAVR

Портировано с PIC16F887 + MicroElektronika C.

  http://embedded-lab.com/blog
       /lab-20-interfacing-a-ks0108-based-graphics-lcd-part-1

------------------------------------------------------------------------

GLCD.prj

; ************************************************************
; PROJECT:
; AUTHOR:
; ************************************************************

; Micro + software running
; ------------------------------------------------------------
.MICRO "ATmega8"
.TOOLCHAIN "GCC"     ; Bug: 1. erase everything, but GLCD.c, GLCD.prj
                     ;      2. use GCC, compile with errors;
                     ;      3. use GENERIC
.GCCPATH   "C:\WinAVR"
.GCCMAKE   AUTO
.TARGET    "GLCD.hex"
.SOURCE    "GLCD.c"

;.TRACE              ; Activate micro trace

; Following lines are optional; if not included
; exactly these values are taken by default
; ------------------------------------------------------------
.POWER VDD=5 VSS=0  ; Power nodes
.CLOCK 1meg         ; Micro clock
;.STORE 250m         ; Trace (micro+signals) storage time

; ------------------------------------------------------------
; Micro nodes: RESET, AREF, PB0-PB7, PC0-PC6, PD0-PD7, ACO, TIM1OVF, ADC6, ADC7
; Define here the hardware around the micro
; ------------------------------------------------------------
;                 RS  RW  E   |<---        data         --->| CS1 CS2 /RST LED+ LED-
Xglcd _graphiclcd PC0 PC1 PC2 PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0 PC4 PC3 VDD  VDD  VSS

------

GLCD.c

#include <math.h>
#include <avr/io.h>
#include <util/delay.h>

// GLCD module connections
#define GLCD_Data   PORTD
#define GLCD_DataIn PIND
#define GLCD_Dir    DDRD

#define GLCD_CS1 PC4
#define GLCD_CS2 PC3
#define GLCD_RS  PC0
#define GLCD_RW  PC1
#define GLCD_EN  PC2
// End GLCD module connections

#define  PORT_ON(port,pin) (port|=(1<<pin))
#define  PORT_OFF(port,pin) (port&=~(1<<pin))

void GLCD_Init( void);
void Enable_Pulse(void);
void GLCD_ON(void);
void GOTO_COL(unsigned int);
void GOTO_ROW(unsigned int);
void GOTO_XY(unsigned int, unsigned int);
void GLCD_Write(unsigned short);
unsigned short GLCD_Read(unsigned short);
void GLCD_Clrln(unsigned short);
void GLCD_CLR(void);
void Draw_Point(unsigned short, unsigned short, unsigned short);
void Fill_Test( void);
void Circle_Test( void);

void Enable_Pulse()
{
    PORT_ON(PORTC,GLCD_EN); // EN high
    _delay_us(5);
    PORT_OFF( PORTC, GLCD_EN); // EN low
    _delay_us(5);
}

void GLCD_ON()
{
    //Activate both chips
    PORT_OFF( PORTC, GLCD_CS1);
    PORT_OFF( PORTC, GLCD_CS2);
    PORT_OFF( PORTC, GLCD_RS); //RS low --> command
    PORT_OFF( PORTC, GLCD_RW); //RW low --> write
    GLCD_Data = 0x3F;          //ON command
    Enable_Pulse();
}

void GOTO_COL(unsigned int x)
{
    unsigned short Col_Data;
    PORT_OFF( PORTC, GLCD_RS);      //RS low --> command
    PORT_OFF( PORTC, GLCD_RW);      //RW low --> write
    if(x<64)                        //left section
    {
        PORT_OFF( PORTC, GLCD_CS1); //select chip 1
        PORT_ON( PORTC, GLCD_CS2);  //deselect chip 2
        Col_Data = x;               //put column address on data port
    }
    else                            //right section
    {
        PORT_OFF( PORTC, GLCD_CS2);
        PORT_ON( PORTC, GLCD_CS1);
        Col_Data = x-64;            //put column address on data port
    }
    Col_Data = (Col_Data | 0x40 ) & 0x7F;  //Command format
    GLCD_Data = Col_Data;
    Enable_Pulse();
}

void GOTO_ROW(unsigned int y)
{
    unsigned short Col_Data;
    PORT_OFF( PORTC, GLCD_RS);     //RS low --> command
    PORT_OFF( PORTC, GLCD_RW);     //RW low --> write
    Col_Data = (y | 0xB8 ) & 0xBF; //put row address on data port set command
    GLCD_Data = Col_Data;
    Enable_Pulse();
}

void GOTO_XY(unsigned int x,unsigned int y)
{
    GOTO_COL(x);
    GOTO_ROW(y);
}

void GLCD_Write(unsigned short b)
{
    PORT_ON( PORTC, GLCD_RS);          //RS high --> data
    PORT_OFF( PORTC, GLCD_RW);         //RW low --> write
    GLCD_Data = b;                     //put data on data port
    _delay_us(1);
    Enable_Pulse();
}

unsigned short GLCD_Read(unsigned short column)
{
    unsigned short read_data = 0; //Read data here
    GLCD_Dir = 0x00;              //PORTD as Input
    PORT_ON( PORTC, GLCD_RW);     //Read 1
    PORT_ON( PORTC, GLCD_RS);     //Data 1
    if (column>63) {
        PORT_ON( PORTC, GLCD_CS1);
        PORT_OFF( PORTC, GLCD_CS2);
    }
    else {                        //Disable/Enable CS2
        PORT_OFF( PORTC, GLCD_CS1);
        PORT_ON( PORTC, GLCD_CS2);
    }
    _delay_us(1);                 //tasu
    PORT_ON( PORTC, GLCD_EN);     //Latch RAM data into ouput register 1
    _delay_us(1);                 //twl + tf

    //Dummy read
    PORT_OFF( PORTC, GLCD_EN);    //Low Enable 0
    _delay_us(5);
    PORT_ON( PORTC, GLCD_EN);     //latch data from output register to data bus 1
    _delay_us(1);                 //tr + td(twh)

    read_data = GLCD_DataIn;      //Input data
    PORT_OFF( PORTC, GLCD_EN);    //Low Enable to remove data from the bus 0
    _delay_us(1);                 //tdhr
    GLCD_Dir = 0xFF;              //Output again
    return read_data;
}

void GLCD_Clrln(unsigned short ln)
{
    int i;
    GOTO_XY(0,ln);              //At start of line of left side
    GOTO_XY(64,ln);             //At start of line of right side (Problem)
    PORT_OFF( PORTC, GLCD_CS1); //0;
    for( i=0; i<65; i++)
        GLCD_Write(0);
}

void GLCD_CLR()
{
    unsigned short m;
    for( m=0; m<8; m++)
        GLCD_Clrln(m);
}

void Draw_Point(unsigned short x, unsigned short y, unsigned short color)
{
    unsigned short Col_Data;
    GOTO_XY(x,(y/8));
    switch (color)
    {
        case 0: // Light spot
            Col_Data = ~(1<<(y%8)) & GLCD_Read(x);
            break;
        case 1: // Dark spot
            Col_Data = (1<<(y%8)) | GLCD_Read(x);
            break;
    }
    GOTO_XY(x,(y/8));
    GLCD_Write(Col_Data);
}

void GLCD_Init( void) {
    GLCD_Dir = 0xFF;            // Output on Data Bus
    DDRC = 0xFF;                // Output on Control Bus + Address Bus
    PORT_ON( PORTC, GLCD_CS1);  // De-Activate both chips 1
    PORT_ON( PORTC, GLCD_CS2);
    GLCD_ON();
    GLCD_CLR();
}

void Fill_Test( void) {
    unsigned short u, v;
    do {
        for(u=0; u<64; u+=1)
            for (v=0; v<128; v+=1)
                Draw_Point(v, u, 1);
        _delay_ms(100);
        GLCD_CLR();
        _delay_ms(100);
    } while(1);
}

void Circle_Test( void) {
    unsigned short u, v;
    double fi;
    do {
        for(fi=0.01; fi<=1.; fi+=.01) {
             u = 64 + 32 * sin( 2 * 3.14 * fi);
             v = 32 + 32 * cos( 2 * 3.14 * fi);
             Draw_Point(u, v, 1);
        }
        _delay_ms(100);
        GLCD_CLR();
        _delay_ms(100);
    } while(1);
}

int main(void) {
    GLCD_Init();
    Circle_Test();
    return 0;
}


