سلام دوستان
من این برنامه رو تو کدویژن نوشتم جواب گرفتم
تو بسکام نوشتم جواب گرفتم
ولی تو atmel studio جواب نمیگیرم
طفا کمک کنید
من این برنامه رو تو کدویژن نوشتم جواب گرفتم
تو بسکام نوشتم جواب گرفتم
ولی تو atmel studio جواب نمیگیرم
طفا کمک کنید
کد:
#define CRYSTAL 20UL//MHZ
#define MHZ 1000000UL
#define F_CPU (CRYSTAL*MHZ)
#include <avr/io.h>
#include <stdio.h> //for fprintf using!
#include <compat/deprecated.h>
#include <util/delay.h>
#include <inttypes.h>
#define bv(bit) (1<<bit)
#define sbi(byte,bit) byte|=bv(bit)
#define cbi(byte,bit) byte&=~bv(bit)
//Data Port////////////////////////////////////////////////////////////
#define LCD_DATA_PORT PORTA
#define LCD_DATA_DDR DDRA
#define LCD_DATA_PIN PINA
//Control Port/////////////////////////////////////////////////////////
#define LCD_CTRL_PORT PORTC
#define LCD_CTRL_DDR DDRC
#define LCD_CTRL_PIN PINC
//Control Pin//////////////////////////////////////////////////////////
#define LCD_RD_BIT 0
#define LCD_WR_BIT 1
#define LCD_RS_BIT 2
#define LCD_CS_BIT 3
#define LCD_RST_BIT 4
///////////////////////////////////////////////////////////////////////
#define RDH() sbi(LCD_CTRL_PORT,LCD_RD_BIT)
#define RDL() cbi(LCD_CTRL_PORT,LCD_RD_BIT)
#define WRH() sbi(LCD_CTRL_PORT,LCD_WR_BIT)
#define WRL() sbi(LCD_CTRL_PORT,LCD_WR_BIT)
#define RSH() sbi(LCD_CTRL_PORT,LCD_RS_BIT)
#define RSL() cbi(LCD_CTRL_PORT,LCD_RS_BIT)
#define CSH() sbi(LCD_CTRL_PORT,LCD_CS_BIT)
#define CSL() cbi(LCD_CTRL_PORT,LCD_CS_BIT)
#define RSTH() sbi(LCD_CTRL_PORT,LCD_RST_BIT)
#define RSTL() cbi(LCD_CTRL_PORT,LCD_RST_BIT)
///////////////////////////////////////////////////////////////////////
void write_8bit(unsigned char _value);
void write_data(unsigned int data);
void write_command(unsigned int command);
void lcd_writereg(unsigned int _cmd , unsigned int _data);
void Lcd_init(void);
void lcd_clear(int color);
void lcd_reset(void);
void lcd_init_port(void);
///////////////////////////////////////////////////////////////////////
#define Black 0x0000
#define Blue 0x001F
#define Red 0xF800
#define Green 0x07E0
#define Cyan 0x07FF
#define Magenta 0xF81F
#define Yellow 0xFFE0
#define White 0xFFFF
///////////////////////////////////////////////////////////////////////
unsigned char HIGH (unsigned int integer);
unsigned char LOW (unsigned int integer);
///////////////////////////////////////////////////////////////////////
int main(void)
{
lcd_init_port();
lcd_reset();
Lcd_init();
lcd_clear(Yellow);
DDRD|=bv(7);
while(1)
{
PORTD^=bv(7);
_delay_ms(1000);
}
}
void lcd_init_port(void)
{
LCD_DATA_DDR=0xff;
LCD_DATA_PORT=0x00;
LCD_CTRL_DDR|= bv(LCD_RD_BIT)|
bv(LCD_WR_BIT)|
bv(LCD_RS_BIT)|
bv(LCD_CS_BIT)|
bv(LCD_RST_BIT);
}
void Lcd_init(void)
{
lcd_reset();
_delay_ms(100);
lcd_writereg (0x0001 , 0x0100);
lcd_writereg (0x0002 , 0x0700);
lcd_writereg (0x0003 , 0x1030);
lcd_writereg (0x0008 , 0x0302);
lcd_writereg (0x0009 , 0x0000);
lcd_writereg (0x000a , 0x0008);
lcd_writereg (0x0010 , 0x0000);
lcd_writereg (0x0011 , 0x0005);
lcd_writereg (0x0012 , 0x0000);
lcd_writereg (0x0013 , 0x0000);
_delay_ms(200);
lcd_writereg (0x0010 , 0x12b0);
_delay_ms(100);
lcd_writereg (0x0011 , 0x0007);
_delay_ms(100);
lcd_writereg (0x0012 , 0x008C);
lcd_writereg (0x0013 , 0x1700);
lcd_writereg (0x0029 , 0x0020);
_delay_ms(100);
lcd_writereg (0x0030 , 0x0000);
lcd_writereg (0x0031 , 0x0106);
lcd_writereg (0x0032 , 0x0101);
lcd_writereg (0x0035 , 0x0106);
lcd_writereg (0x0036 , 0x0203);
lcd_writereg (0x0037 , 0x0000);
lcd_writereg (0x0038 , 0x0707);
lcd_writereg (0x0039 , 0x0204);
lcd_writereg (0x003C , 0x0106);
lcd_writereg (0x003D , 0x0103);
lcd_writereg (0x0050 , 0x0000);
lcd_writereg (0x0051 , 0x00EF);
lcd_writereg (0x0052 , 0x0000);
lcd_writereg (0x0053 , 0x013F);
lcd_writereg (0x0060 , 0xA700);
lcd_writereg (0x0061 , 0x0001);
lcd_writereg (0x0090 , 0x0030);
lcd_writereg (0x0007 , 0x0133);
}
void lcd_writereg(unsigned int _cmd , unsigned int _data)
{
write_command(_cmd);
write_data(_data);
}
void lcd_reset(void)
{
CSH();
RDH();
WRH();
RSH();
RSTH();
_delay_ms(20);
RSTL();
_delay_ms(1000);
RSTH();
_delay_ms(20);
}
void write_command(unsigned int command)
{
RDH();
RSL();//COMMAND
CSL();
write_8bit(HIGH(command));
write_8bit(LOW(command));
RSH();
CSH();
}
void write_data(unsigned int data)
{
RDH();
RSH();//DATA
CSL();
write_8bit(HIGH(data));
write_8bit(LOW(data));
RSH();
CSH();
}
void write_8bit(unsigned char _value)
{
WRL();
LCD_DATA_PORT = _value;
WRH();
}
void lcd_clear(int color)
{
int i,j;
lcd_writereg(0x0020 , 0x0000);
lcd_writereg(0x0021 , 0x0000);
write_command(0x0022);
for(i=0;i<320;i++)
for(j=0;j<240;j++)
write_data(color);
}
unsigned char HIGH(unsigned int integer)
{
return ( (integer>>8) & 0xff);
}
unsigned char LOW(unsigned int integer)
{
return (integer&0xff);
}


دیدگاه